Can I use IIF inside IIF?

M

Minnow

I have a query using an IIF clause, it works fine. But when I add another IIF
inside, it tells me syntax error. Any idea? The SQL code is as bellow:
SELECT A.[Customer ID], A.[Year], A.[Month], a.reading, iif( A.Unit='L',
IIF(A.Note=‘New Count’, A.[Reading], A.[Reading]-B.[Reading]),
HourToLiter(A.[Reading]-B.[Reading])) AS mProcessed
FROM [Monthly Reading] AS A INNER JOIN [Monthly Reading] AS B ON
(A.[Customer ID] = B.[Customer ID]) AND (A.[Year]*12 + A.Month -1 =
B.[Year]*12 + B.Month)
ORDER BY A.[Customer ID], a.Month;


Thanks for all consideration.
 
J

JohnFol

Might be worth breaking it down to see if the nesting or the statement
causes the problem, ie:

Select
iif( A.Unit='L', "Unit = L" , HourToLiter(A.[Reading]-B.[Reading]),
IIF(A.Note='New Count', A.[Reading], A.[Reading]-B.[Reading]),
.......
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top