Hi there...
I'm trying to write a query where I (AFAIK) need to use NOT IN with a case statement...see the code snippet below:
Now I'm getting the "standard" "Incorrect syntax near ',' on the THEN line. Unless I'm truly braindead this morning I cant find a comma formatting error, so it must be in the use of the list after the THEN. I just can't seem to find another way to do this. I thought about using a subquery, but in the same notion I need the SUM(), and you can't put a subquery in the aggregate.
For the record, I need to do this in the actual statement & not in the WHERE clause as the options directly affect this one part of the query, not the full statement.
Thanks for your assistance.
Samalie
I'm trying to write a query where I (AFAIK) need to use NOT IN with a case statement...see the code snippet below:
Code:
SUM(CASE WHEN YEAR(t.umonth) = (YEAR('12/01/2007')-1)
AND MONTH(t.umonth) = 12
AND t.ibook = 1
AND p.scode NOT IN (CASE WHEN p2.scode = '.slp'
AND YEAR('12/01/2007')-1 = 2006
THEN ('003','014','023','026','059','069','070','073','077','079','080','087','storwp')
WHEN p2.scode = '.pvlp'
AND YEAR('12/01/2007')-1 = 2006
THEN ('003','004','008','015','023','024','041','059','063','064','068','069','070','073','077','079','080','storwp')
ELSE ('02346986123461986')
END)
THEN CONVERT(decimal(14,2),(ISNULL(t.sbegin,0) * ((isnull(lp.dpercent,100) / 100))))
+ CONVERT(decimal(14,2),(ISNULL(t.smtd,0) * ((isnull(lp.dpercent,100) / 100))))
ELSE 0
END)
Now I'm getting the "standard" "Incorrect syntax near ',' on the THEN line. Unless I'm truly braindead this morning I cant find a comma formatting error, so it must be in the use of the list after the THEN. I just can't seem to find another way to do this. I thought about using a subquery, but in the same notion I need the SUM(), and you can't put a subquery in the aggregate.
For the record, I need to do this in the actual statement & not in the WHERE clause as the options directly affect this one part of the query, not the full statement.
Thanks for your assistance.
Samalie