I am working on code from a person who held my position 2+ years ago, and am having trouble deciphering a block of their SQL code.
WHERE ACCOUNT NOT IN (SELECT ACCOUNT
FROM MWAPPTS A1
WHERE A1.ACCOUNT = A.ACCOUNT
AND ADATE > dbo.Endofmonth(ACTIONDATE)
AND REASON IN ('CPE','NPPE')
AND USERFLAG IN ( 'U', 'B' ))
dbo.Endofmonth is a stored procedure which gets the last day of the month for the inputed date.
If I am reading that right, we are not including rows where the account would be returned by the select statement shown. I am having problems with the select statement though. Am I correct that it is getting ACCOUNT where ADATE is older than the end of the month. The reason IS “CPE” or “NPPE”, and the USERFLAG is either “U”, or “B”?
Yes, you are returning the records where the account does not have the following:
1) an
ADATEgreater than the date returned by the functiondbo.Endofmonth(ACTIONDATE).2) a
Reasonthat isCPE or NPPE3) and the
Userflagis eitherU or B.You would have to look at the code in the function
dbo.Endofmonth(ACTIONDATE)to determine exactly what it is returning.