0

我想将此案别名为 Brutobedrag,但我无法完成。

SELECT     
    Invoices.InvoiceNr AS Factuurnummer, 
    case(Invoices.IsDebit)
        when 0 then -1*(Invoices.NetAmount + Invoices.BTW + COALESCE (Invoices.BPM, 0)) 
        else Invoices.NetAmount + Invoices.BTW + COALESCE (Invoices.BPM, 0)
    end 
from
    Brands INNER JOIN
    Invoices ON Brands.Id = Invoices.Brand INNER JOIN
    SalesPersons ON Invoices.SalesPerson = SalesPersons.Id LEFT OUTER JOIN
    Payments ON Invoices.Id = Payments.InvoiceId

where
    Invoices.InvoiceDate > '2011-12-31'

group by
    Invoices.InvoiceNr,
    Invoices.NetAmount,
    invoices.BTW,
    invoices.BPM,
    Invoices.IsDebit
4

2 回答 2

0
case when Invoices.IsDebit = 0 
     then -1*(Invoices.NetAmount + Invoices.BTW + COALESCE (Invoices.BPM, 0)) 
     else Invoices.NetAmount + Invoices.BTW + COALESCE (Invoices.BPM, 0)
end as Brutobedrag 
于 2013-09-27T10:56:53.787 回答
0

当它是'BC'

SELECT (CASE 'BC' WHEN 'BC' THEN 1 WHEN 'AC' THEN 4 WHEN 'CL' THEN 3 ELSE ' ' END ) UNION (SELECT (CASE 'BC' WHEN 'BC' THEN 2 ELSE ' ' END)) UNION (SELECT (CASE 'BC' WHEN 'BC' THEN 22 ELSE ' ' END)) UNION (SELECT (SELECT (CASE 'BC' WHEN 'BC' THEN 24 ELSE ' ' END)) UNION (SELECT (CASE 'BC' WHEN 'BC ' 那么 5 ELSE ' ' END))

回答:1 2 5 22 24

将使用 FULL 来获得具有单一条件的多个值以防万一

于 2014-01-03T13:43:30.277 回答