I am trying in the below query (which is going to be a subquery of another larger query) to convert a VARCHAR to a value which can be measured as either <0 or >0 - not sure exactly what value to use. I am getting the error "operand data type is invalid in the sum operator"
this is the very first time I encountered this. The ultimate goal is to say "when the value is 'L' then return 0, else return 1" additionally DEL_INDICATOR
is a field in thePO_ITEM
table but I omitted in the SELECT.
Here is the Updated code:
SELECT G.order_no AS 'GPS_ORDER_#',
G.order_status AS 'GPS_ORDER_STATUS',
G.cst_order_no AS 'GPS_CUSTOMER_PO_#',
H.PO_NUMBER AS 'SAP_PO_#',
P.PO_ITEM_NUMBER,
P.DEL_INDICATOR
FROM
(SELECT order_no,
order_status,
cst_order_no
FROM asagdwpdx_prod.dbo.SimoxOrder1
UNION ALL
SELECT order_no,
order_status,
cst_order_no
FROM asagdwpdx_prod.dbo.SimoxOrder2
UNION ALL
SELECT order_no,
order_status,
cst_order_no
FROM asagdwpdx_prod.dbo.SimoxOrder3) G
JOIN PDX_SAP_USER.dbo.VW_PO_HEADER H ON G.order_no = H.AHAG_NUMBER
JOIN PDX_SAP_USER.dbo.VW_PO_ITEM P ON H.PO_NUMBER = P.PO_NUMBER
WHERE G.order_status = '10'
AND NOT EXISTS (
SELECT P1.PO_NUMBER,
P1.PO_ITEM_NUMBER,
SUM(CASE
WHEN CAST(P1.DEL_INDICATOR AS INT) = 'L'
THEN '0'
ELSE '1'
END AS [SUM_DEL]) AS [SUM]
FROM PDX_SAP_USER.dbo.VW_PO_ITEM P1
WHERE P1.PO_NUMBER = H.PO_NUMBER
GROUP BY P1.PO_NUMBER,
P1.PO_ITEM_NUMBER,
CASE
WHEN P1.DEL_INDICATOR = 'L'
THEN '0'
ELSE '1'
END
HAVING SUM (CASE
WHEN CAST(P1.DEL_INDICATOR AS INT) = 'L'
THEN '0'
ELSE '1'
END) > '0')