Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ProEdge
Yak Posting Veteran
64 Posts |
Posted - 2005-10-28 : 02:09:11
|
Does anyone know if it's possible to return a row of non-null data only? This does't mean replacing any null columns with data but esentially returning only those columns that do have data in it. So for example, I could have a table that looks something like this:title_id title author date------ ---- ------ ----- 1 A James Baker 12/05/7=87 2 B <NULL> 04/23/68 3 C Rita Haywood 10/51/82 So if I query title_id = 3 and ask for title, author and date, my returned result set will only include "B" and "04/23/68." Is this possible? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-28 : 02:54:56
|
| do you mean this?Select Columns from yourTable where title_id=3 and author is not nullMadhivananFailing to plan is Planning to fail |
 |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2005-10-28 : 03:27:13
|
| Are you talking about dynamically creating a select statement based on the non-null value?Why do you want to do this? How will you code against a resultset that can return any combination of columns? Are you doing this solely for presentation? If so, do it in that layer.Nathan Skerl |
 |
|
|
ProEdge
Yak Posting Veteran
64 Posts |
Posted - 2005-10-28 : 13:17:12
|
| I've never heard of a dynamic select statement but yes, it is for presentation. So I may return the result set and bind it to a Repeater, for example, in a .NET page. The problem is I don't know if SQL can return such a result in one Select statement. |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-10-28 : 15:12:15
|
| You should never do this. Your stored procedures and SELECT's should always return a constant number of columns. If some are Null, then your presentation layer (in this case, ASP.NET) simply can display whatever it wants in that situation. Templates in ASP.NET make this very, very easy. Especially when you use a Repeater, which has no inherent UI and you completely define yourself how the output will be.In addition, how can you databind your control if sometimes the data ommits certain columns? If you are still stuck on how to display the data the way you want, post some questions in the ASP.NET forum here (with detailed information and examples), but trust me when I tell you that your database calls should return a constant number of columns. |
 |
|
|
binggeli
Starting Member
20 Posts |
Posted - 2005-10-28 : 15:33:29
|
| Hmmm . . . I see where you're coming from. If everything else fails, you can always use the ISNULL() function within SQL Server.SELECT title_id, title, ISNULL(author, 'n.a.'), date FROM . . .Whatever you use for the "replacement value" must be of the same data type as the expected result.Hope that helps. |
 |
|
|
|
|
|
|
|