总和字段中的空值 [英] null values in sum field

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

问题描述

SELECT     SUM(totalhanks) AS Expr1, colorcode, subcontractrowid, yarncode
FROM         dbo.tb_yarnissuereg
GROUP BY colorcode, subcontravtrowid, yarncode





sum      color  subcontractrowid         yarncode
NULL	4	2012-2013/200/102/1/1	 2/60001
NULL	4	2012-2013/200/102/1/1	2/60001p
NULL	4	2012-2013/200/102/1/2	2s
NULL	4	2012-2013/200/102/12/1	2/60001p
NULL	4	2012-2013/200/102/8/1	2/60002
NULL	4	2012-2013/200/102/8/3	2/60001p
NULL	6	2012-2013/200/102/13/2	3s
NULL	7	2012-2013/200/102/13/1	7s
NULL	8	2012-2013/200/102/8/1	4s
NULL	8	2012-2013/200/102/8/3	3s
4422	9	2012-2013/200/102/12/1	2/60001p


如何避免总和字段中的这些空值


how can i avoid these null values in sum field

推荐答案

使用ISNULL.

试试:
Use ISNULL.

Try:
SELECT     SUM(ISNULL(totalhanks,0)) AS Expr1, colorcode, subcontractrowid, yarncode
FROM         dbo.tb_yarnissuereg
GROUP BY colorcode, subcontravtrowid, yarncode



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



Refer: MSDN: ISNULL (Transact-SQL)[^]


嘿.不想在合计列中使用空值
请尝试以下查询...

hey.. if you don''t want null values in sum column
try below query...

SELECT     SUM(totalhanks) AS Expr1, colorcode, subcontractrowid, yarncode
FROM         dbo.tb_yarnissuereg
GROUP BY colorcode, subcontravtrowid, yarncode
HAVING SUM(totalhanks) is not null


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

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