update query with insertion?
i need a query which have to do both update and insert..
first i have to check this condition
SELECT TOP 1 * FROM NEC_Customer_DB_Map where DB_AvailabilityFlag = 'Y'
and if DB_AvailabilityF开发者_Go百科lag = 'Y'
i have to update this 'Y'
as 'ASSIGNED'
and also i
have to insert by using
INSERT INTO NEC_Customer_DB_Map(NEC_CustomerCode,NEC_CustomerName) VALUES(@NEC_CustomerCode,@NEC_CustomerName)
can anyone combine these into one query..Any Suggestion?
Since your question is tagged with sql-server-2008 you could consider usinge the MERGE-statement:
http://technet.microsoft.com/en-us/library/bb510625.aspx
You could use a where
clause to make the insert conditional:
INSERT INTO NEC_Customer_DB_Map(NEC_CustomerCode,NEC_CustomerName)
SELECT @NEC_CustomerCode,@NEC_CustomerName
WHERE EXISTS (SELECT * FROM NEC_Customer_DB_Map where DB_AvailabilityFlag = 'Y')
精彩评论