Convert SQL column null values to 0

database, sql, sql-server

Solution

You can use ISNULL (Transact-SQL)

eg

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

Problem

I'm new to SQL Server and I have an issue. I have this view, in which some of the columns from the formulas are allowed to be null. How could I convert these null values to 0 because if they are null, the result of the formula it will be also null. Thanks! ``` 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 ```

Original source