We can't see your data. We can't see what is in your macro variables. So we are guessing. But here is my guess. SImplify this part of your query:
and (c.srcstcd not in ('5','6') or c.srcstcd is null)
and (d.pur_id not in ('0001234','0005678') or d.pur_id is null)
Even if the query were working successfully, you would get the same result by using:
and (c.srcstcd not in ('5','6') )
and (d.pur_id not in ('0001234','0005678'))
After all, if c.srcstcd is null, the first condition about it not being '5' or '6' would capture the observation. So even if this doesn't turn out to be the source of your error, at least you can simplify the program without changing the meaning of the query.
... View more