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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Query

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 GR
4 GL
4 SO
5 AU
6 GL
etc....

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 advance
Kabir

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
Go to Top of Page

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 t
where not exists (select * from table x where x.UserID = t.UserID and x.Country = 'GL')
group by UserID
[/code]


KH

Go to Top of Page
   

- Advertisement -