The text of this article is not in this database — only its details are. Read it on the old site: Using Case With Select and Update Statement in SQL Server 2012
1 Comment
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.

Jiyaul MustaphaPosted Jul 23, 2019, 2:08 AM
DECLARE @JCnt int=nullSEt @JCnt=(SELECT COUNT( ISNUll(EmpCode,0)) FROM tbl_Employees WHERE EmpCode=1 ) UPDATE #TempCode SET janCA= CASE WHEN @JCnt>0 THEN (SELECT SUM (ISNUll(Amount,0)) FROM tbl_Salary WHERE Code=1 )ELSE 0 END WHERE code=1