SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Insert if not exist
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

fadius
Starting Member

USA
1 Posts

Posted - 04/08/2013 :  15:54:24  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3724 Posts

Posted - 04/08/2013 :  16:22:50  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 04/09/2013 :  00:23:35  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000