View Single Post
  #4 (permalink)  
Old April 9th, 2009, 10:18 AM
pixelwiz pixelwiz is offline
Registered User
 
Join Date: Mar 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding conditional Update if already exists or Insert

Hi, Do you have any idea how I could modify that query to not only do inserts, but to first check if a record exists, and update it and if not then insert.

I've done that with a single row updates like this:
UPDATE tracking
SET search_dt = GETDATE()
WHERE cc_id = #cc_id#
AND zip = '#getCustomer.zip#'
IF @@ROWCOUNT = 0
BEGIN
INSERT INTO tracking
(cc_id, zip, search_dt)
VALUES
(#cc_id#, '#getCustomer.zip#', GETDATE())
END

But I have no idea how to combine the loading from XML part with this type of logic or even if that's possible...

Thanks,
-Roman
Reply With Quote