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 2005 Forums
 Transact-SQL (2005)
 Insert Help

Author  Topic 

learntsql

524 Posts

Posted - 2010-09-06 : 07:06:53
Hi All,
I have a table which already has some records,
When i insert new data how to ignore codes which are already there.
Can i use join caluse or should i write Sub Query.
TIA.

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-09-06 : 07:12:14
u can use not exists(), not in too

if not exists(select 'x' from tbale_name where codes='xxxx')
insert into table_name....

insert into table_name....
where codes not in('xxxx','yyyy')

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -