| Author |
Topic |
|
Ads
Starting Member
23 Posts |
Posted - 2012-06-18 : 12:32:15
|
| Hi,I currently have the below query which works really well. However I would like to have the query so that it reads like this: IF EXISTS - UPDATE and INSERT ELSE INSERTIs it possible to integrate the and insert? IF EXISTS (SELECT * FROM [QuasarTest2].[dbo].[tradersaddresses] WHERE traderid = 'ADLA01') UPDATE [QuasarTest2].[dbo].[tradersaddresses] set isackaddress = 0, isdeladdress = 0, isinvaddress = 0, ismainaddress = 0, isstataddress = 0 WHERE [QuasarTest2].[dbo].[tradersaddresses].[traderid] like 'ADLA01' ELSE INSERT INTO [QuasarTest2].[dbo].[tradersaddresses] (traderid, addressid, street, city, county, postcode, countryid, areaid, currencyid, vatcatid, nlcatid, isexportaddress, isforeigndomcurrency, isexchfixedatorder, pricelistid, eutransportid, languageid, isackaddress, isdeladdress, isinvaddress, ismainaddress, isstataddress, tradertype, createddate, companyid, olversionnumber) VALUES ('ADLA01', 1, 'TEST', 'TEST2', 'TEST3', 'TEST4', 'GB', 'UK', 'STG', 1, 0, 0, 0, 0, 'PLUK', 1, 'GBR', 1, 0, 1, 1, 1, 'C', getdate(), 'RFS', 0) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-18 : 12:35:46
|
then make it like IF EXISTS (SELECT * FROM [QuasarTest2].[dbo].[tradersaddresses] WHERE traderid = 'ADLA01')BEGIN UPDATE [QuasarTest2].[dbo].[tradersaddresses] set isackaddress = 0, isdeladdress = 0, isinvaddress = 0, ismainaddress = 0, isstataddress = 0 WHERE [QuasarTest2].[dbo].[tradersaddresses].[traderid] like 'ADLA01' ENDINSERT INTO [QuasarTest2].[dbo].[tradersaddresses] (traderid, addressid, street, city, county, postcode, countryid, areaid, currencyid, vatcatid, nlcatid, isexportaddress, isforeigndomcurrency, isexchfixedatorder, pricelistid, eutransportid, languageid, isackaddress, isdeladdress, isinvaddress, ismainaddress, isstataddress, tradertype, createddate, companyid, olversionnumber) VALUES ('ADLA01', 1, 'TEST', 'TEST2', 'TEST3', 'TEST4', 'GB', 'UK', 'STG', 1, 0, 0, 0, 0, 'PLUK', 1, 'GBR', 1, 0, 1, 1, 1, 'C', getdate(), 'RFS', 0)------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Ads
Starting Member
23 Posts |
Posted - 2012-06-19 : 04:12:06
|
| Thanks very much!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-19 : 14:13:16
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|