sql - 将 SQL 列空值转换为 0

标签 sql sql-server database

我是 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

最佳答案

好吧,有人应该为 ANSI 标准说句话:

coalesce(<column>, 0)

isNULL 特定于数据库(甚至在某些数据库中做不同的事情)。

关于sql - 将 SQL 列空值转换为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13726276/

相关文章:

sql-server - 在列上创建唯一约束会自动创建索引吗?

php - 将同一张表上的多个 MySQL 查询合并为一个

database - Oracle 数据库 : ORA. 01034:ORACLE 不可用

sql - AlwaysOn 可用性组监听器访问

MySQL 具有 union/join 和同一列上的两个别名

sql - 有没有办法将表中每列值限制为只有 1 行?

c++ - 高效更新多条记录的 SQLite 表

sql - Postgres 根据客户端返回不同的结果

sql-server - SQL Server SELECT FOR XML 如何获取同一级别的两个元素

sql-server - 为什么SQL Server停止执行?