Click here to Skip to main content
15,896,522 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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 .
Posted

1 solution

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
 
Share this answer
 
Comments
Aadyakumar 14-Jun-14 7:18am    
Thanks for your replay

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900