Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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 = WORKFROM 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' ENDFROM POP_PRNA AS POP ,ONLY_PRNA AS PRWHERE POP.RCD_CD = PR.RCD_CDAND POP.M_PAY_FLAG <> 1
note sure why you use '' in 0 comparison statement