Hello All,
I am trying to run a comparison query on Net Pay results over a four week period. Right now the data the query returns contains NULL values for specific weeks. I would like to convert these NULL values into 0's so I can average the Net Pay for all four weeks. I have been trying to use the CASE function, but WinSQL doesn't seem to like the way I am writing it. Here is the portion of the code where I am trying to implement the CASE function. I've also included one of the temp tables I am using.
NET_TMP_THREE
(EMPLID, NET_PAY, PAY_END_DT)
AS
(
SELECT A.EMPLID, B.NET_PAY, B.PAY_END_DT
FROM NET_PAY A LEFT OUTER JOIN PS_PAY_CHECK B
ON A.EMPLID = B.EMPLID
AND B.PAY_END_DT = '2007-10-14'
)
SELECT
A.COMPANY, A.PAYGROUP, A.PAYCHECK_NBR, A.OFF_CYCLE, A.EMPLID, A.EMPL_RCD, A.NAME,
A.DEPTID, A.SSN, A.PAY_END_DT, (CASE WHEN CHAR(A.NET_PAY)= 'NULL' THEN CHAR(A.NET_PAY) = '0' END) AS WEEK_1,
B.PAY_END_DT, (CASE WHEN CHAR(B.NET_PAY)= 'NULL' THEN CHAR(B.NET_PAY) = '0' END) AS WEEK_2, C.PAY_END_DT,
(CASE WHEN CHAR(C.NET_PAY)= 'NULL' THEN CHAR(C.NET_PAY) = '0' END) AS WEEK_3, D.PAY_END_DT,
(CASE WHEN CHAR(D.NET_PAY)= 'NULL' THEN CHAR(D.NET_PAY) = '0' END) AS WEEK_4
FROM NET_PAY A LEFT OUTER JOIN NET_TMP_ONE B
ON A.EMPLID = B.EMPLID
LEFT OUTER JOIN NET_TMP_TWO C
ON A.EMPLID = C.EMPLID
LEFT OUTER JOIN NET_TMP_THREE D
ON A.EMPLID = D.EMPLID
Here is the error I am receiving when I attempt to run it:
SQL0104N An unexpected token "=" was found following "THEN CHAR(A.NET_PAY)". Expected tokens may include: "CONCAT". SQLSTATE=42601
Can anyone offer me some assistance on this. Thank you
I am trying to run a comparison query on Net Pay results over a four week period. Right now the data the query returns contains NULL values for specific weeks. I would like to convert these NULL values into 0's so I can average the Net Pay for all four weeks. I have been trying to use the CASE function, but WinSQL doesn't seem to like the way I am writing it. Here is the portion of the code where I am trying to implement the CASE function. I've also included one of the temp tables I am using.
NET_TMP_THREE
(EMPLID, NET_PAY, PAY_END_DT)
AS
(
SELECT A.EMPLID, B.NET_PAY, B.PAY_END_DT
FROM NET_PAY A LEFT OUTER JOIN PS_PAY_CHECK B
ON A.EMPLID = B.EMPLID
AND B.PAY_END_DT = '2007-10-14'
)
SELECT
A.COMPANY, A.PAYGROUP, A.PAYCHECK_NBR, A.OFF_CYCLE, A.EMPLID, A.EMPL_RCD, A.NAME,
A.DEPTID, A.SSN, A.PAY_END_DT, (CASE WHEN CHAR(A.NET_PAY)= 'NULL' THEN CHAR(A.NET_PAY) = '0' END) AS WEEK_1,
B.PAY_END_DT, (CASE WHEN CHAR(B.NET_PAY)= 'NULL' THEN CHAR(B.NET_PAY) = '0' END) AS WEEK_2, C.PAY_END_DT,
(CASE WHEN CHAR(C.NET_PAY)= 'NULL' THEN CHAR(C.NET_PAY) = '0' END) AS WEEK_3, D.PAY_END_DT,
(CASE WHEN CHAR(D.NET_PAY)= 'NULL' THEN CHAR(D.NET_PAY) = '0' END) AS WEEK_4
FROM NET_PAY A LEFT OUTER JOIN NET_TMP_ONE B
ON A.EMPLID = B.EMPLID
LEFT OUTER JOIN NET_TMP_TWO C
ON A.EMPLID = C.EMPLID
LEFT OUTER JOIN NET_TMP_THREE D
ON A.EMPLID = D.EMPLID
Here is the error I am receiving when I attempt to run it:
SQL0104N An unexpected token "=" was found following "THEN CHAR(A.NET_PAY)". Expected tokens may include: "CONCAT". SQLSTATE=42601
Can anyone offer me some assistance on this. Thank you