Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sqldev6363
Yak Posting Veteran
54 Posts |
Posted - 2011-01-13 : 10:15:28
|
| i have a table result like thisID Present State1 y IL2 y VA 3 NULL NULL4 y CA5 NULL NULL6 NULL NULLI have second table like thisID Present State3 Y TX5 Y NJ6 NULL NULLThe thing is i have put the values from secondtable into first tablei need the result like thisID Present State1 y IL2 y VA 3 Y TX4 y CA5 Y NJ6 NULL NULLCan i get a query for the above logic..i am very much new to this sqlserver..thanks in advancedev |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-01-13 : 10:22:16
|
| [code]UPDATE t1SET Present = t2.Present, State = t2.StateFROM Table1 t1JOIN Table2 t2On t1.ID = t2.ID;[/code] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-01-13 : 10:38:44
|
| if you want only NULL values to be get updated better to add a where condition like belowesp when table2 have more records than in sample which already has values presentWHERE t1.Present IS NULLAND t1.State IS NULL------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|