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 |
|
smcallister
Starting Member
15 Posts |
Posted - 2009-06-05 : 15:00:56
|
| I have 12 rows in table with a column called "type". There are 4 rows with type "1", 4 rows with type "2", and 4 rows with type "3".Depending on which PHP page I'm on, I want to be able to pull up all type "X" and then below that list the rest of the rows ordered by type.So for instance, this would appear on "items.php?type=2":Dog Type 2Cat Type 2Frog Type 2Fish Type 2Car Type 1Plane Type 1Train Type 1Bike Type 1House Type 3Condo Type 3Apt Type 3Hotel Type 3 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-06-05 : 15:15:15
|
| try this:order by CASE WHEN type = @type then -1 else type endBe One with the OptimizerTG |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-07 : 03:12:40
|
| order by NULLIF(type,@type) |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-06-07 : 08:05:40
|
quote: Originally posted by visakh16 order by NULLIF(type,@type)
This won't satisfy the requirement where the all rows with the type value of @type appears first in the list then all the others in natural order.Your solution would fit solve a different problem where @type was a nullable input to sort by.Be One with the OptimizerTG |
 |
|
|
|
|
|