Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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')
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 MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs