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 |
|
harshal_in
Aged Yak Warrior
633 Posts |
Posted - 2003-07-02 : 02:10:30
|
| hello,if I have a table with three columns a int ,b varchar(50),c intin the column c the values are repeated. suppose there are 300 rows in the table.now is it possible to sort the record selection according to a specific value of column c? I mean if there are 35 rows with value 2109 in column c then is it possible to list all the rows with 2109 first and then list the remaining rows?I know it is possible using #table and stored procedure ,any easier method ?Thanks in advance,Regards,Harshal.The Judgement of the Judge is as good as the Judge. |
|
|
Andraax
Aged Yak Warrior
790 Posts |
Posted - 2003-07-02 : 02:26:19
|
| Use CASE...select *from fooorder by CASE when c=2109 then 0 else 1 end, a, b, c |
 |
|
|
harshal_in
Aged Yak Warrior
633 Posts |
Posted - 2003-07-03 : 01:15:24
|
quote: Use CASE...select *from fooorder by CASE when c=2109 then 0 else 1 end, a, b, c
thanks.this is exactly what I was looking forthanks again,regards,harshalThe Judgement of the Judge is as good as the Judge. |
 |
|
|
harshal_in
Aged Yak Warrior
633 Posts |
Posted - 2003-07-04 : 04:59:14
|
quote: Use CASE...select *from fooorder by CASE when c=2109 then 0 else 1 end, a, b, c
Ok this worked very fine but the requirements again changed.first sort by c=2109 i.e show all the records with c=2109 and after that the remaining the records according to the datesis it possible?thanks in advance,harshal.The Judgement of the Judge is as good as the Judge. |
 |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2003-07-04 : 05:01:47
|
| isn't that what the query does already?-------Moo. |
 |
|
|
Andraax
Aged Yak Warrior
790 Posts |
Posted - 2003-07-04 : 05:07:30
|
| What dates? There were no date columns in your table definition. Could you clarify what you mean by dates? If you want to, post your DDL for the table. |
 |
|
|
harshal_in
Aged Yak Warrior
633 Posts |
Posted - 2003-07-04 : 05:45:27
|
quote: What dates? There were no date columns in your table definition. Could you clarify what you mean by dates? If you want to, post your DDL for the table.
ok sorry for the confusion created.the query which I am trying to form is the collection of columns from various tables.And there is a datefield in the selection so I want to resort the remaining values according to that datefield.The Judgement of the Judge is as good as the Judge. |
 |
|
|
Andraax
Aged Yak Warrior
790 Posts |
Posted - 2003-07-04 : 06:56:37
|
| Just put it after the case in the order by clause:order by CASE when c=2109 then 0 else 1 end, datefieldThis will sort so that all records which have c=2109 will appear first, ordered by datefield. Then all other records will appear, ordered by the datefield. |
 |
|
|
|
|
|
|
|