INSERT query for a table?(Using two Tables)
-
Hi I stuck at an INSERT Query using two tables. I have two tables Table1 and Table2.In Table1 I have 2 columns,one with dupicate value and another with null values.In Table2 I have 2 columns,both the columns have unique values. Now I have to INSERT values from Table2 to Table1 with the corresponding or maching values like Table1 StateCode StateName --------- ---------- AK NULL AK NULL AK NULL AL NULL AL NULL AL NULL CO NULL CO NULL CO NULL Table2 StateCode StateName --------- ---------- AK Alaska AL Alabama AR Arkansas AZ Arizona CA California CO Colorado I have to INSERT values into Table1 in the null column from Table2 w.r.t StateCode. Help me :confused: Suggest me an example. I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu
-
Hi I stuck at an INSERT Query using two tables. I have two tables Table1 and Table2.In Table1 I have 2 columns,one with dupicate value and another with null values.In Table2 I have 2 columns,both the columns have unique values. Now I have to INSERT values from Table2 to Table1 with the corresponding or maching values like Table1 StateCode StateName --------- ---------- AK NULL AK NULL AK NULL AL NULL AL NULL AL NULL CO NULL CO NULL CO NULL Table2 StateCode StateName --------- ---------- AK Alaska AL Alabama AR Arkansas AZ Arizona CA California CO Colorado I have to INSERT values into Table1 in the null column from Table2 w.r.t StateCode. Help me :confused: Suggest me an example. I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu
Hi Chandu Sounds like you need to "update". Something like:
update Table1 set StateName = Table2.StateName from Table2 where Table2.StateCode = Table1.StateCode
Regards Andy
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message".