如果该列的总和为零或为null,则从输出中删除一列 [英] Remove a column from out put, if the sum of that column is zero or null
本文介绍了如果该列的总和为零或为null,则从输出中删除一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我有一个带有'n'列数的表格,由于旋转,它是动态的。在输出中,一些列的总和为零或为空。所以我想从输出中删除这些列。
有人请尽快给出建议,我最近两天都被困在这里。
解决方案
从这个例子改编:
声明@zerosumcolumn int
声明@nullcolumn int
set @ zerosumcolumn = 0
set @nullcolumn = 0
if(
(从table1中选择sum(zerosumcolumn))= 0
)
begin
set @zerosumcolumn = 1
结束
if(
(从table1中选择sum(isnull(nullcolumn,0))= 0
)
begin
set @nullcolumn = 1
结束
如果(@zerosumcolumn = 1且@nullcolumn = 1)
begin
从table1选择nonzerosumcolumn
结束
else if(@zerosumcolumn = 1)
开始
选择nonzerosumcolumn,nullcolumn from table1
end
else if(@nullcolumn = 1)
begin
选择nonzerosumcolumn,zerosumcolumn from table1
结束
其他
开始
select * from table1
end
Dear All,
I have a table formed out put with 'n' number of columns , it is dynamic because of pivoting . In the out put sum of some columns are zero or null . so i want to remove those columns from the output.
Some one please give an advice as soon as possible, i am stuck here last two days .解决方案Adapt from this example:
declare @zerosumcolumn int declare @nullcolumn int set @zerosumcolumn = 0 set @nullcolumn = 0 if ( (select sum(zerosumcolumn) from table1) = 0 ) begin set @zerosumcolumn = 1 end if ( (select sum(isnull(nullcolumn, 0)) from table1) = 0 ) begin set @nullcolumn = 1 end if (@zerosumcolumn = 1 and @nullcolumn = 1) begin select nonzerosumcolumn from table1 end else if (@zerosumcolumn = 1) begin select nonzerosumcolumn, nullcolumn from table1 end else if (@nullcolumn = 1) begin select nonzerosumcolumn, zerosumcolumn from table1 end else begin select * from table1 end
这篇关于如果该列的总和为零或为null,则从输出中删除一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文