August 3, 2005 at 12:18 pm
I have this result from a SQL command
year Mb Ca Si Ca Cu Nq Tg
----------------------------
1999 0 4 55 0 2 0 1
2000 1 7 88 0 3 0 1
I need the some SQL commands what brings the following result:
year Mb Ca Si Cu Tg
---------------------
1999 0 4 55 2 1
2000 1 7 88 3 1
Observe what the Ca e Nq collumns was not showed because his sum is equal zero.
How do I make this?
Thanks a lot again.
Alex Sandro
August 3, 2005 at 12:23 pm
Simple solution > do it application side.
Other solution. Prerun the query like this :
Select case when sum(dtName.Col1) = 0 then 'Col1' else null as Col1,
case when sum(dtName.Col2) = 0 then 'Col2' else null as Col2....
from (Primary select statemet) dtName
Then use that select to not show those columns at the application side.
August 3, 2005 at 1:21 pm
Thanks for the help !
But in my case, it doesnt works. I need to what the collumns with sum is equal zero dont came in the result of the sql command.
Its because the application what will to show the results dinamically create the grid with the columns from the SQL command. If the result came with 84 collumns, the application will show 84 collumns.
Some case, I just need to see 5 of them. How I saied before, I really need what the other 79 collumns dont came in the SQL result.
Some sugestion...
Once more time thanks.
August 3, 2005 at 1:24 pm
Prerun the query to find the columns to hide.
Remake the sql statement with dynamic sql and run that statement. This will be a pain to code really.
August 3, 2005 at 2:33 pm
I have used ALTER TABLE to insert columns into a #TempTable using Dynamic SQL in the past. That may be a possible approach to ease the pain. I agree with Remi that this will not be easy...
I wasn't born stupid - I had to study.
August 3, 2005 at 2:38 pm
Just a newbie question here... can't the columns of datagrid be manipulated in some way?? I know we can change the fonts/colors... but is there a way to change the size or visibility? I think it would be much simler than to try to do this.
August 3, 2005 at 3:39 pm
I know from my past with this, grids are often third party components and a real bear to alter. I whole-heartedly agree with Remi, though. If you can do this on the Client-side, you will be much happier with the results.
I wasn't born stupid - I had to study.
August 4, 2005 at 9:36 am
It sounds as though you'll need to query for each column separately, then use that to build your field list for a dynamic SQL statement.
Loop through fields
Is field sum 0
If not add field to SQL string
Call sp_executeSQL with your SQL string.
August 4, 2005 at 11:34 am
-- get colnames
Select @STR= case when sum(dtName.Col1) <> 0 then 'Col1' else '' end +
case when sum(dtName.Col2) <> 0 then ',Col2' else '' end +
case when sum(dtName.Col3) <> 0 then ',Col3' else '' end + ...
from (Primary select statemet) dtName
-- Check for initial comma
if Left(@str,1) = ','
set @STR = Substring(@str,2,len(@str)-1)
--execute it
exec ( 'select ' + @STR + 'from Yourselectstatement' )
* Noel
August 4, 2005 at 11:38 am
Now you're agreeing with us .
August 4, 2005 at 1:21 pm
Well, most of the time I DO
* Noel
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply