Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help me improve this Update code

Author  Topic 

nvakeel
Yak Posting Veteran

52 Posts

Posted - 2008-02-19 : 12:11:04
Is it possible to write these in single update?

UPDATE POP_PRNA
SET WORK = WK_M
FROM POP_PRNA AS POP ,
ONLY_PRNA AS PR
WHERE
POP.RCD_CD = PR.RCD_CD
AND POP.M_PAY_FLAG <> 1
AND ISNULL(WORK,'') in ('0.00','0')



----------------------------------------------------------------------------------------------
UPDATE POP_PRNA
SET WK_M = WORK
FROM POP_PRNA AS POP ,
ONLY_PRNA AS PR
WHERE
POP.RCD_CD = PR.RCD_CD
AND POP.M_PAY_FLAG <> 1
AND ISNULL(WORK,'') < ISNULL(WK_M,'')



-----------------------------------------------------------------------------------------------
UPDATE POP_PRNA
SET WORK = '0'
FROM POP_PRNA AS POP ,
ONLY_PRNA AS PR
WHERE
POP.RCD_CD = PR.RCD_CD
AND POP.M_PAY_FLAG <> 1
AND ISNULL(WORK,'') <= '0'

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-19 : 12:16:23
Try this:-
UPDATE POP_PRNA 
SET WORK = CASE WHEN ISNULL(WORK,'') in ('0.00','0') THEN WK_M END,
WK_M = CASE WHEN ISNULL(WORK,'') < ISNULL(WK_M,'') THEN WORK END,
WORK = CASE WHEN ISNULL(WORK,'') <= '0' THEN '0' END
FROM POP_PRNA AS POP ,
ONLY_PRNA AS PR
WHERE
POP.RCD_CD = PR.RCD_CD
AND POP.M_PAY_FLAG <> 1


note sure why you use '' in 0 comparison statement
Go to Top of Page
   

- Advertisement -