我是SQL Server的新手,但遇到了问题。

我有此 View ,其中公式中的某些列允许为空。

我如何将这些空值转换为0,因为如果它们为空,则公式的结果也将为空。

谢谢!

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

最佳答案

您可以使用ISNULL (Transact-SQL)

例如

(isnull(price,0)+isnull(notarycosts,0)) as Total

08-25 12:27