我寫了這個來創建過去30天的發票摘要。在檢查發票時,我注意到我拉了很多空值,因爲大多數客戶都是免稅的。我想提出一個IF聲明(如果t.TAXABL_23 ='N'然後是使稅收= 1的東西...它在這裏變得有點灰) 在這個混亂的地方if語句會去,或者更好的是使用一個IF語句是這樣做的邏輯方法。 謝謝。我在哪裏放置if語句?
Select c.ordnum_31 as "Sales Order Number",
c.invce_31 as "Invoice Number",
c.custpo_31 as "Job Name",
c.ordid_31 as "Other Job Name",
c.invdte_31 as "Invoice Date",
cast (sum((1-(m.DSCRTE_23/100)) * (o.price_32 * o.shpqty_32)) as decimal (8,2)) as "Net Amount",
cast (c.frtamt_31 as decimal(8,2)) as Freight,
cast(((t.TAXRTE_25 * .01) * c.TAXTOT_31) as decimal (8,2)) as Tax,
cast (c.MSCAMT_31 as decimal(8,2)) as MISC,
cast(round (sum((1-(m.DSCRTE_23/100)) * (o.price_32 * o.shpqty_32)) + c.frtamt_31 + c.MSCAMT_31 + ((t.TAXRTE_25 * .01) * c.TAXTOT_31),1) as decimal(8,2)) as "Invoice Total"
from Invoice_Master c
left join Invoice_Detail o on c.ORDNUM_31 = o.ORDNUM_32
left join Customer_Master m on c.CUSTID_31 = m.CUSTID_23
left join Tax_master t on m.TXCDE1_23 = t.TAXCDE_25
where c.invdte_31 >= DATEADD(day,-30, getdate())
group by
c.ORDNUM_31,
c.CUSTID_31,
c.INVCE_31,
c.CUSTPO_31,
c.ORDID_31,
c.INVDTE_31,
c.frtamt_31,
c.taxtot_31,
m.dscrte_23,
c.MSCAMT_31,
t.taxrte_25
order by "Invoice Number"
它們實際上是否爲NULL或是否是N''? – BJones
你可以包含一些樣本數據和預期的輸出嗎? –
@bjones,如果納稅標誌是N,則它們爲NULL。 – Onyxtacular