Skip to content
Advertisement

Sum IIF in T-SQL

a need a help with T-SQL, I have an query to select current row and subtract with previous row. The goal is SUM results from IIF and group by date and shift.

the query:

the error that is displayed

Example data:

Advertisement

Answer

If I understand correctly, you need to do the lag() in a subquery:

I also strongly encourage you to use coalesce() because it is standard SQL. IIF() is retrofit to support MS Access-style queries.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement