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 |
|
yoggi123
Starting Member
29 Posts |
Posted - 2005-01-14 : 08:00:45
|
| Hey,I am not sure how to really explain this, but I'll give it a try.I am looking to use a select statement in a way that I can tell it which rows to insert in depending on when only one result is returned. For example, if I run this statement:SELECT Column1, Column2, Column3FROM #Temp1The result set is:Column1---Column2---Column399--------6756756---55555 44--------55---------NULLColumn3 as only the one returned value, so I do not want it associated with any of the other rows, so I need this:Column1---Column2---Column3NULL------NULL------5555599--------6756756---NULL44--------55---------NULLAnother example:The returned result now is:Column1---Column2---Column3---Column499---------6756756---55555-----NULL42---------55--------NULL------12345So I need:Column1---Column2----Column3----Column4NULL-------NULL-------55555------NULLNULL-------NULL-------NULL-------1234599---------6756756----NULL-------NULL 44---------55---------NULL-------NULL Does this make sense, and/or is it even possible?I know it could be more of a presentation thing, but I would like to know how to do it in the code behind.Thanks |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-01-17 : 00:42:35
|
Something like thisSelect case when((select column3 from table where column1=T.Column1)<>"") then null else column1 end, case when((select column3 from table where column2=T.Column2)<>"") then null else column2, column3, column4 from Table T Madhivanan |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-01-17 : 01:22:59
|
| You could use the union operator to construct the resultsetselect col1, col2, null as col3 from tab where ...union allselect null as col1, null as col2, col3 from tab where ...rockmoose |
 |
|
|
|
|
|
|
|