Reputation: 356
I have a LineItem table.
InvoiceNo ApplyTax(bool) Subtotal
1 1 10
1 0 10
1 1 10
2 0 10
2 1 10
Apply Tax means adding another 7% to subtotal
I need a select statement that returns.
InvoiceNo Total
1 31.4 ----(10* 1.07 + 10 + 10*1.07)
2 20.7 ----( 10* 1.07 + 10)
I could come up with this but its giving syntax error.
SELECT InvoiceNo ,SUM(( select case(ApplyTax) WHEN 1 THEN 1.07 ELSE 1)*subtotal)
From InvoiceTable
Group By InvoiceNo
Am i missing something really simple? I can't get it right.
Upvotes: 0
Views: 77
Reputation: 7288
Put END
at the end of your CASE
statement..
SELECT inv ,SUM(( select case(ApplyTax) WHEN 1 THEN 1.07 ELSE 1 END)*subtotal) as total
From test
Group By inv
Upvotes: 0
Reputation: 1269553
Here is the proper syntax:
SELECT InvoiceNo, SUM((case ApplyTax WHEN 1 THEN 1.07 ELSE 1 end)*subtotal)
From InvoiceTable
Group By InvoiceNo ;
Notice there is no nested select
statement and the case
ends with end
.
Upvotes: 1