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 |
|
KabirPatel
Yak Posting Veteran
54 Posts |
Posted - 2007-05-25 : 06:56:53
|
| Hi,I have a table as follows:UserID Country----------------4 GR4 GL4 SO5 AU6 GLetc....I want to insert the country GL in all instances where it does not already exist in the table. e.g. in the above table I would want in inserted for UserID 5 but not 4 and 6 as these already have GL.I have tried using a self join but got into a knot. Can anybody help?Thanks in advanceKabir |
|
|
damuchinni
Starting Member
29 Posts |
Posted - 2007-05-25 : 07:02:26
|
| Hi Kabir,Give me more infromation, i.e even userid 4 has GR and So is that, it ia also to be updated with country GL |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-05-25 : 07:13:40
|
[code]insert into table (UserID, Country)select UserID, 'GL'from table twhere not exists (select * from table x where x.UserID = t.UserID and x.Country = 'GL')group by UserID[/code] KH |
 |
|
|
|
|
|