| Author |
Topic |
|
goligol
Posting Yak Master
128 Posts |
Posted - 2011-10-13 : 12:57:48
|
| Hi, I have a table1 which only has one column, and another table2 which is more complete and has more information. I am adding a column to table1 (descriptions) and trying to retrieve information form table2 realated to the rows in the table1:select a.hs_code ,a.descriptions = CASE WHEN a.hs_code = b.hs_code THEN a.descriptions = b.hs_code_desc END from table1 a, table2 bany clue? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-13 : 13:07:30
|
| [code]update aset a.descriptions = b.hs_code_desc from table1 ainner join table2 bon a.hs_code = b.hs_code [/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
goligol
Posting Yak Master
128 Posts |
Posted - 2011-10-13 : 13:20:57
|
| it still generate error:select a.hs_code ,a.descriptions update aset a.description = b.hs_code_desc from table1 ainner join table2 bon a.hs_code = b.hs_codeError:Msg 4104, Level 16, State 1, Line 1The multi-part identifier "a.hs_code" could not be bound.Msg 4104, Level 16, State 1, Line 2The multi-part identifier "a.descriptions" could not be bound.Msg 207, Level 16, State 1, Line 8Invalid column name 'descriptions'. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-13 : 13:33:15
|
no need of select just useupdate aset a.description = b.hs_code_desc from table1 ainner join table2 bon a.hs_code = b.hs_code ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
goligol
Posting Yak Master
128 Posts |
Posted - 2011-10-13 : 13:55:15
|
| when I use the above commends is still shows the following error:Invalid column name 'hs_code_desc'. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-14 : 01:20:23
|
| do you've the column 'hs_code_desc' in table2?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
goligol
Posting Yak Master
128 Posts |
Posted - 2011-10-14 : 11:13:06
|
| Yes I have it in table2 but in table1 I have to generate this coulum and make it equal to a'hs_code_desc' in table2 when a.hs_code = b.hs_code.Thank you |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-14 : 11:15:23
|
what do you mean by generate? do you mean you need to add it? then use likealter table table1 add hs_code_desc <data type same as in table2> nullupdate aset a.hs_code_desc = b.hs_code_desc from table1 ainner join table2 bon a.hs_code = b.hs_code make sure you give data type same as table2------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|