Click here to Skip to main content
15,306,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I select only columns that don't have null value

col1 col2 col3
20    12   null
25    null     null

Desired output

col1 col2 
20    12  
25    null


What I have tried:

Not getting way to come out.......................................................
Posted
Updated 13-Jan-17 2:29am

1 solution

The structure of the result set is static in nature. In other words, you decide the columns when you build the query.

As far as I can see, you have few options:

1. first run a query to see which columns contain data and then run a query again with dynamically built SELECT clause containing only desired columns
2. Fetch the data into a single, XML column, handle appropriately
3. Fetch all the columns and handle formatting on client side

From those, option 3 makes most sense since SQL isn't designed for formatting, just fetching and manipulating data.
   

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