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 |
|
agarwasa2008
Posting Yak Master
109 Posts |
Posted - 2009-11-05 : 18:22:50
|
| Hi,I have a query with isProduct set to (1 bit, null). I want the result set to be ordered by isProduct1 or isProduct2 values equal to true or 1 (it does not matter which one) to be on top. How can i do that? The way I have it currently. It does the first column correctly but the 2nd column is dependent on the first one and so all the true records are not on the top for the isProduct2 column. Please advice. select a.isProduct1, a.isProduct2, a.col1, a.col2, b.col1 from table1 a join table 2 b on b.id= a.id Join table 3 c on c.name = a.name where a.col1 = '1245' order by a.isProduct1, a.isproduct2SA |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-11-05 : 18:58:27
|
| Do you have nulls in a column of bit data type?JimEveryday I learn something that somebody else already knew |
 |
|
|
agarwasa2008
Posting Yak Master
109 Posts |
Posted - 2009-11-05 : 19:00:23
|
| yesSA |
 |
|
|
agarwasa2008
Posting Yak Master
109 Posts |
Posted - 2009-11-05 : 19:47:54
|
| I would be curious to know if this is even possible?SA |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-11-05 : 20:20:25
|
| Maybe something like this will help?order by ISNULL(a.isProduct1,0) DESC, ISNULL(a.isproduct2,0) DESCJimEveryday I learn something that somebody else already knew |
 |
|
|
agarwasa2008
Posting Yak Master
109 Posts |
Posted - 2009-11-05 : 20:42:42
|
| It works correctly. I have never seen that syntax before can u explain it to me please. Thanks this is a life saver for me.Thanks again!!SA |
 |
|
|
|
|
|