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
 General SQL Server Forums
 New to SQL Server Programming
 inserting

Author  Topic 

codrgiii
Starting Member

29 Posts

Posted - 2009-05-30 : 18:17:36
how do i insert into a table and only inserting once if there are more than one of the same value in that table/column? i want it to only insert once if there are more than one of the same value, to avoid inserting duplicate values yet still inserting other values from that column to the table without terminating the script, how do i do this?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-05-30 : 19:09:53
If you mean that your source table has duplicates then construct your SELECT statement such that only one value is selected using GROUP BY or DISTINCT.
If you mean that your target table already has one or more of the values from your source table then use either a LEFT OUTER JOIN where the left table (target table) is NULL. OR use a WHERE NOT EXISTS clause.

If you need specifics then post your code.

Be One with the Optimizer
TG
Go to Top of Page

codrgiii
Starting Member

29 Posts

Posted - 2009-05-30 : 21:00:31
what would be the syntax for that?
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-05-30 : 21:29:08
I think all the scenarios I mentioned are in these examples. Get used to using Books Online. It's a great resource.
http://msdn.microsoft.com/en-us/library/ms187731(SQL.90).aspx


Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -