Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Given either of the two following datasets

Kağıt Cinsi        Sarı      Yeşil      Mavi

Kalın                4         0          5
İnce               null        0          3

or

Kağıt Cinsi        Sarı      Yeşil      Mavi

Kalın                4         0          5
İnce                 0         0          3

I want to filter via either a stored procedure or a custom view to hide any column which contains a row with either a 'null' or 'zero' value.

These are the results: I would expect from either of the above datasets

Kağıt Cinsi       Mavi

Kalın               5
İnce                3

I'm not sure what a query for this looks like, but I want to return it from the database like this.

share|improve this question

closed as off topic by Jack Douglas, gbn, jcolebrand Oct 4 '11 at 15:15

Questions on Database Administrators Stack Exchange are expected to relate to database administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Do you now mean "hide column if all values are null or zero". or "hide column if any value is null or zero"? –  gbn Oct 4 '11 at 9:21
    
@gbn -hide column if any value is null or zero. –  Cell-o Oct 4 '11 at 9:24
    
So for row "İnce", Sarı is zero, why is it in the output? –  gbn Oct 4 '11 at 9:28
    
Closing as off-topic because this is a programming/presentation issue (as indicated by the accepted answer) and not a database issue. The question would also likely be closed or migrated on Stack Overflow as is. Since it has an answer, I'm letting it lie, but future readers please know that I will have cleaned up the question to make it a little more digestable. –  jcolebrand Oct 4 '11 at 15:18

2 Answers 2

up vote 3 down vote accepted

This should NOT be done inside the database. There are several levels to any application:

  • Data Layer (where the data is stored and retrieved from)
  • ...
  • Presentation Layer (where the data is displayed/visualised/presented)

As a good rule, the data layer should not dynamically exclude certain columns based on their values (rows yes, columns no). This is the responsibility of the Presentation Layer to hide/display a column based on an arbitrary value.

Depending on what you're using as your presentation layer (C#, Excel, php, etc...) I would ask this question on stackoverflow...

share|improve this answer

You can't hide a column dynamically unless you use dynamic SQL. This quickly gets complicated: what if the zeros are in different columns on different rows? What should the output be

If the zeros/nulls are in the same column, then you can "hide" a column by not selecting it.

SELECT 
   Kağıt Cinsi, Sarı, Mavi
FROM
   MyTable
WHERE
   (Yeşil IS NULL OR Yeşil = 0)

You may not need the filter here: I added it because the question was unclear

share|improve this answer
    
@gbn- As you mentioned,If the zeros/nulls are in different columns on different rows,I want to hide the column.I've updated my question. –  Cell-o Oct 4 '11 at 9:18
    
@Cell-o: well, you need dynamic SQL to query a column to decide whether to add it to the output. Good luck –  gbn Oct 4 '11 at 9:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.