Conditional Update/SQLServer Stored Proc - TechRepublic
General discussion
December 19, 2000 at 02:45 AM
frankus

Conditional Update/SQLServer Stored Proc

by frankus . Updated 25 years, 6 months ago

The following SQL Server Stored Procedure code portion (in the attached Word doc written in T-SQL) is working correctly. It represents a pattern in the procedure which is taking the largest chunk of execution time. Since the condition shown in eachUPDATE block is exclusive of the others, I want to rewrite it so that each successive block only looks at records which have not already met the conditions of the previous ones, etc. The present code searches the whole table in each UPDATE block.My problem lies in rewriting it by using nested IF logic in T-SQL.

UPDATE TableA
SET FieldNew=”OTHER LIAB”
WHERE CC_Code = “OL” AND Kol = “01”

UPDATE TableA
SET FieldNew=”OTHER”
WHERE CC_Code = “AL” AND Kol = “60”

UPDATE TableA
SET FieldNew=”OTHER”
WHERE CC_Code <> “CL” AND CC_Code <> “CP” AND CC_Code <> “03” AND Kol = “31”

UPDATE TableA
SET FieldNew=”DISABILITY”WHERE PP_Code = “IA” AND (CC_Code = “WI” OR CC_Code = “DI”)

UPDATE TableA
SET FieldNew=”MEDICAL”
WHERE PP_Code = “IA” AND (CC_Code = “MD” OR CC_Code = “WR” OR CC_Code = “WM”)

This discussion is locked

All Comments