将0分配给表中的空字段 [英] Assign 0 to null fields in a table

查看:87
本文介绍了将0分配给表中的空字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用左连接加入了两个表。我的结果表中有一些空字段。我需要为那些字段分配0(零)。请在单一行中帮助我。(考虑这个表是查询的结果。所以它没有名字)

I joined two tables using "left join". There are some null fields in my result table.I need to assign 0(zero) to those fields.Please help me with in single queary line.(Consider this table is a result of an query.So it hasn''t a name)

推荐答案

例如

e.g.
select Product_id,Product_name,IsNull(Product_Price,0) from tbl



快乐编码!

:)


Happy Coding!
:)


如果您正在谈论检索值,那么:

If you are talking of retrieving values then:
SELECT 
  someFields,
  IsNULL(fieldThatCanbeNullAndNeedsReplacement, 0)
FROM
  myTable



参考:MSDN:ISNULL(Transact-SQL) [ ^ ]


查询中的用例语句如.....



选择col1,col2,

case

当yourColumn3为NULL然后为0

else yourColumn3

结束YourColumnName

from your_Table



它可以解决您的问题
Use case statement in query like .....

select col1, col2,
case
when yourColumn3 IS NULL then 0
else yourColumn3
end as YourColumnName
from your_Table

it may solve your problem


这篇关于将0分配给表中的空字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆