[英]Convert SQL column null values to 0
我是SQL Server的新手,我有一個問題。
我有這個觀點,其中公式中的一些列被允許為null。
我怎么能將這些空值轉換為0,因為如果它們為null,則公式的結果也將為null。
謝謝!
CREATE VIEW vwAchizitii
AS
SELECT
ac_id
,[Company]
,No
,[ContractID]
,[Seller]
,[AcquistionDate]
,[Village]
,[Commune]
,[Area]
,[PlotArea]
,[FieldNo]
,[Topo1]
,[Topo2]
,[Topo3]
,[Topo4]
,[Topo5]
,[TotalAreaSqm]
,[OwnershipTitle]
,[CadastralNO]
,[Type]
,[Price]
,[NotaryCosts]
,[LandTax]
,[OtherTaxes]
,[AgentFee]
,[CadastralFee]
,[TabulationFee]
,[CertSarcini]
,[ProcuraNO]
,(price+notarycosts+landtax+othertaxes+agentfee+cadastralfee+tabulationfee+certsarcini) as TotalCosts
,(price+notarycosts+landtax+othertaxes+agentfee+cadastralfee+tabulationfee+certsarcini)/(TotalAreaSqm/10000) as RonPerHa
,(price+notarycosts+landtax+othertaxes+agentfee+cadastralfee+tabulationfee+certsarcini)/(TotalAreaSqm/10000*FixHist) as EurPerHa
,[DeclImpunere]
,[FixHist]
,(price+notarycosts+landtax+othertaxes+agentfee+cadastralfee+tabulationfee+certsarcini)/FixHist as EurHist
,[LandStatus]
FROM
nbAchizitii
好吧,有人應該為ANSI標准說一句話:
coalesce(<column>, 0)
isNULL
特定於數據庫(甚至在某些數據庫中做不同的事情)。
嘗試這個:
ISNULL([nullable field], 0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.