|
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
|
|
|
| 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?
| |
|
| 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?
|
|
|
|
|