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 2008 Forums
 Transact-SQL (2008)
 Insert if not exist

Author  Topic 

fadius
Starting Member

1 Post

Posted - 2013-04-08 : 15:54:24
I have a spreadsheet I was given of people and the ID. I have the insert statement in the last row and it works. My problem is I dont want it to insert if it already exsist.

INSERT INTO PROVIDERID (PROVIDERID_K, PROVIDER_K, TYPE_RTK, ID, USERDEF_RTK1, USERDEF_RTK2, USERDEF_RTK3, ACTIVE, WEBPUBLISHSTATUS_RTK) VALUES ('ID58395', 'D2AX0MH9UO', 'D2QK0IXBT7', 'GCI9503', ' NONE', ' NONE', ' NONE', 1, ' NONE')

If a Provider_K already has a row of type_rtk, I don't want it to insert and skip this provider_k all together. ANy help would be greatly appreciated.

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-08 : 16:22:50
You can use a "if not exists" clause like shown below.
if not exists
(select * from PROVIDERID where PROVIDER_K = 'D2AX0MH9UO' and TYPE_RTK='D2QK0IXBT7')
INSERT INTO PROVIDERID (PROVIDERID_K, PROVIDER_K, TYPE_RTK, ID, USERDEF_RTK1, USERDEF_RTK2, USERDEF_RTK3, ACTIVE, WEBPUBLISHSTATUS_RTK)
VALUES ('ID58395', 'D2AX0MH9UO', 'D2QK0IXBT7', 'GCI9503', ' NONE', ' NONE', ' NONE', 1, ' NONE')
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-09 : 00:23:35
do you just have this single insert or do you need to do same for group of insert statement?
If its latter, you may be better off generating the sql using excel funcions

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -