Click to See Complete Forum and Search --> : db2 sql


jrthor2
11-15-2007, 08:59 AM
I have the below sql that returns me the userid of users who have entered a weight on our weight table that have had the same weight for 3 days two times. It works if I don't add the first_name, last_name, email_address in the select part, and if I don't have the crm.userid uid in the from. How can I get this to work with these pieces of information returned? I get this error:

Error Code: -119, SQL State: 42803] DB2 SQL error: SQLCODE: -119, SQLSTATE: 42803, SQLERRMC: EMAIL_ADDRESS

SELECT CRCWT_USERID, FIRST_NAME, LAST_NAME, EMAIL_ADDRESS
FROM CRM.CRCWT_CUSTOMER_WEIGHT CWT,
CRM.USERID UID
WHERE EXISTS
(SELECT 1
FROM CRM.CRCWT_CUSTOMER_WEIGHT B
WHERE CWT.CRCWT_USERID = B.CRCWT_USERID
AND CWT.CRCWT_WEIGHT = B.CRCWT_WEIGHT
AND B.CRCWT_WTDATE = CWT.CRCWT_WTDATE - 1 DAY
)
AND EXISTS
(SELECT 1
FROM CRM.CRCWT_CUSTOMER_WEIGHT B
WHERE CWT.CRCWT_USERID = B.CRCWT_USERID
AND CWT.CRCWT_WEIGHT = B.CRCWT_WEIGHT
AND B.CRCWT_WTDATE = CWT.CRCWT_WTDATE - 2 DAYS
)
GROUP BY CRCWT_USERID
HAVING COUNT(*) = 2

Thanks

jrthor2
11-15-2007, 11:00 AM
I got this working.