Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Multiple update statements with different conditions in a merge procedure

$
0
0
Hi All,


I have a merge procedure which runs fine 

and the condition for when matched is like this


WHEN MATCHED 
AND 
tODS_StoreTraffic.NumVisits <> tODS_StoreTrafficStg.NumVisits    
AND
(
(tODS_StoreTrafficStg.TrafficExceptionId  IS NOT NULL AND tODS_StoreTrafficStg.NumVisits < @Threshold)  
)
THEN    
UPDATE
SET 
tODS_StoreTraffic.NumVisits = tODS_StoreTrafficStg.NumVisits,
ModifiedDate= GETDATE(),
ModifiedUser=SUSER_NAME()




This condition runs fine, Not i have to add one more case to this condition 



such as 


AND 
tODS_StoreTraffic.NumVisits <> tODS_StoreTrafficStg.NumVisits    
AND
(
(tODS_StoreTrafficStg.TrafficExceptionId  IS NULL AND tODS_StoreTrafficStg.NumVisits > @Threshold)  
)
THEN    
UPDATE
SET 
tODS_StoreTraffic.OrigVisits = tODS_StoreTrafficStg.NumVisits



I am unable to use these 2 conditions in a single when matched case, can someone please help me with this?


Thanks.



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>