在SQL表中,我有一列,其中值包含季度或空值。 [英] In SQL table I have column where value consists quarterly or null value.

查看:99
本文介绍了在SQL表中,我有一列,其中值包含季度或空值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在sql表中我有一个列,其中value包含Quarterly或Null值。

我在传递时写了一个StoreProcedure参数iam无法获取NULL值数据。



我尝试过:





在sql表中我有列,其中value包含Quarterly或Null值。
我在传递参数时写了一个StoreProcedure,我无法获取NULL值的数据。

解决方案

在SQL中,NULL传播 - 所以如果你添加一个包含NULL的列,你将获得NULL作为总结果:

  SELECT   1  +  NULL  +  2  



因此,如果您对列执行任何聚合操作,并且存在NULL值,则会得到NULL结果。

单向循环是在查询中使用ISNULL:

  SELECT  SUM(ISNULL(MyColumn, 0 )) FROM  MyTable 

将列中的所有NULL值视为零。



如果这不是你遇到的问题,那么你需要更详细地解释一下y问题是。


根据您在上面分享的查询和详细信息,我相信您希望在结果的频率列中显示MONTHLY和QUARTERLY。如果这是你需要的,那么试试下面 -

  SELECT   CASE   WHEN  FREQUENCY  IS   NULL   THEN  '  MONTHLY'  ELSE  '  Quarterly'  END   AS  FREQ,* 
FROM MASTER





如果这不是你想要的,请告诉我。



谢谢: )


Hi,

In sql table i have column where value consists Quarterly or Null value.
I have written a StoreProcedure when passing parameters iam unable to get data of NULL Values.

What I have tried:

Hi,

In sql table i have column where value consists Quarterly or Null value.
I have written a StoreProcedure when passing parameters iam unable to get data of NULL Values.

解决方案

In SQL NULLs propagate - so if you add a column that contains a NULL, you will get NULL as the total result:

SELECT 1 + NULL + 2


So if you are performing any aggregate operation on your column, and a NULL value exists, you will get a NULL result.
One way round this is to use ISNULL in your query:

SELECT SUM(ISNULL(MyColumn, 0)) FROM MyTable

Will treat all NULL values in the column as zero.

If this isn't the problem you are having, then you need to explain in much better detail exactly what you problem is.


Based on the the query and details you have shared above, I believe you are looking to show "MONTHLY" and "QUARTERLY" in the frequency column of the result. If this is what you need then try following-

SELECT CASE WHEN FREQUENCY IS NULL THEN 'MONTHLY' ELSE 'Quarterly' END AS FREQ,* 
FROM MASTER



Please let me know if this is not what you wanted.

Thanks :)


这篇关于在SQL表中,我有一列,其中值包含季度或空值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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