我已經在MY SQL服務器中創建視圖,其中我需要使用CASE
條件來滿足需求。如何在SQL視圖中創建新列時使用條件
select
cast([SIR Per Occ] as float) * 1000000 as [SIR Per Occ],
cast([SIR Agg] as float) * 1000000 as [SIR Agg],
cast([Per Occ Limit Between] as float) * 1000000 as [Per Occ Limit Between],
cast((cast([SIR Per Occ] as float)) + (cast([Per Occ Limit Between] as float)) as float) * 1000000 as [Policy Occ Attachment],
cast((cast([SIR Agg] as float)) + (cast([Per Occ Limit Between] as float)) as float) * 1000000 as [Policy Agg Attachment]
from IT.dbo.Policy_find
但在我的任務,如果[Per Occ Limit Between]
是NULL
值,那麼我就需要假設它是零和上面的代碼應該是工作爲以下邏輯:
Policy Occ Attachment = [SIR Per Occ]
Policy Agg Attachment = [SIR Agg]
我將如何實現這種情況在select子句中沒有使用where
的條件?
情況下,當[每測站極限的]爲null,則0,否則,投([每測站極限的作爲浮動)* 1000000年底爲[每測站極限的] ..這個工作在某種程度上,但它仍然認爲0作爲字符串,並不加起來 – Mike
你仍然可以使用CAST在你的情況? 'CAST(如果exp THEN 0 ELSE 1 END,float)'這有點矯枉過正,但應該可以正常工作 – Lostblue