sql server - Update data from one table to another with no common identifier -


i'd have query (sql server 2012) following: update data 1 table there no common linkable record (pretty sure can't join , update). similarity tables of same structure

to keep simple (transferring 100+ items)

  • table 1a: key, tagname <-- a.tagname 'tag1'
  • table 1b: ds_key, make, model <-- source of update data
  • table 2a: key, tagname <-- b.tagname 'tag2'
  • table 2b: ds_key, make, model <-- destination of update data

so,

  • table 1a: 123, tag1
  • table 1b: 123, test1, model1
  • table 2a: 456, tag2
  • table 2b: 456, null, null

what have:

 --query 1  select key, tagname, ds_key, make, model  table1a  join table1b  on table1a.key = table1b.ds_key  tagname = 'tag1' 

result(123, tag1, 123, test1, model1)

 --query 2  select key, tagname, ds_key, make, model  table2a  join table2b  on table2a.key = table2b.ds_key  tagname = 'tag2' 

result(456, tag2, 456, null, null)

returns mix want work with. getting baffled on how update table2b point. can't join them (at least don't see how!). maybe union all? hope don't need

  update table2b    set table2b.make =    (select make table1a   join table1b   on table1a.key = table1b.ds_key)   table2a   join table2b   on table2a.key = table2b.ds_key   table2a.tagname = 'tag2' 

like said, have 100 records set , seems there needs easier way. in advance , please excuse syntax errors i'm trying paraphrase question keep simple (and i'm tired!) :)

in general, when want update 1 table values table, syntax this:

update tablea set tablea.value = tableb.value  tablea inner join tableb on tablea.key = tableb.key 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -