Home > Archive > MS SQL Server MSEQ > June 2005 > Insert non duplicate data









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Insert non duplicate data
Leo

2005-06-22, 11:23 am

I'm trying to construct an insert statement which will only insert data if it
hasn't been inserted before in the same table, i.e. insert x,y into table
where not exists (select x,y from table), or some such statement. Is there an
easy way of doing this - maybe an if statement that selects x,y and if they
don't exist they are inserted? What would the syntax of such a query be?

2005-06-25, 8:23 pm

INSERT INTO test (X,Y)
SELECT '1','2'
WHERE NOT EXISTS(SELECT 1 FROM test WHERE X='1' AND Y='2')

"Leo" <Leo@discussions.microsoft.com> wrote in message
news:1736A83A-FA81-46CA-A95A- 4D0582E28BFC@microso
ft.com...
> I'm trying to construct an insert statement which will only insert data if
> it
> hasn't been inserted before in the same table, i.e. insert x,y into table
> where not exists (select x,y from table), or some such statement. Is there
> an
> easy way of doing this - maybe an if statement that selects x,y and if
> they
> don't exist they are inserted? What would the syntax of such a query be?



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com