如何在sql server中将null设置为零 [英] how to set null to zero in sql server
问题描述
你好
我有一张桌子,在那张桌子上各个字段都有一些字段为空。
假设我想获取所有价值,例如
select * from tablename
所有的价值。
我需要将null替换为零的值,我不知道哪些字段为空。我想获取如下的查询:select * from tablename。
如果有任何解决方案请帮助。
Hello
I have a table and on that table various fields are there some fields are null.
Suppose i want to fetch all the value like
select * from tablename
It fetch all the value.
I need that the value which are null it will replace to zero and i don''t know which fields are null. I want to fetch query like : select * from tablename.
If any solution then please help.
推荐答案
您好,
您可以使用ISNULL
SQL的功能。ISNULL
函数将使用您指定的值替换空值。
请参阅以下文章,了解有关ISNULL $的更多信息c $ c>功能。
ISNULL-MSDN [ ^ ]
Hi,
you can make use ofISNULL
function of SQL.ISNULL
function will replace the null value with the value you specify.
refer below article for more onISNULL
function.
ISNULL-MSDN[^]
--Example,
SELECT ISNULL(col1, 0), ISNULL(col2, 0), ISNULL(col3, ''), ISNULL(col4, GETDATE()) FROM TableName
我也建议使用*
在选择查询中不是好习惯。指定列名。
希望它有所帮助。
also, i suggest, using "*"
in select query is not good practice. specify the column names.
hope it helps.
使用ISNULL关键字使空列返回值为0. br />
例如:
SELECT ISNULL(column1,0),ISNULL(column2,0)FROM TABLENAME
干杯。 :)
Make use ISNULL keyword to make null columns return value as 0.
For ex:
SELECT ISNULL(column1,0) , ISNULL(column2,0) FROM TABLENAME
cheers. :)
选择Nvl(ColName,0)作为ColNAme来自TabName
ColName:列名,如果它是Null则将显示0,否则将显示其值。
TabName:表名称
Select Nvl(ColName,0) As ColNAme From TabName
ColName: Column Name, if it is Null then 0 will be displayed else its value will be displayed.
TabName: Table Name
这篇关于如何在sql server中将null设置为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!