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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Custome order by

Author  Topic 

forum.nasum
Starting Member

4 Posts

Posted - 2008-04-09 : 12:42:59
Hi,
I have 10 rows in my table, it has int as primary key, (Autogen).
I need to take rows in my custome format, I can't use desc, asc on existinc column.. I need to provide order by giving a row no. sequence.
Can you tell me how to do that?
like order by pk (......).

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-09 : 12:47:26
DIdnt get what you're asking for. Can you give some sample data & o/p to make this clear?
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-09 : 12:54:35
How do you propose to assign sequence no. to rows?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

forum.nasum
Starting Member

4 Posts

Posted - 2008-04-09 : 13:02:34
I mean i need like
Table
PK Name
1 SRI
2 Durga
5 Deepa
7 Kiran

I need a select stmt
where I can get result

SRI
DEEPA
DURGA
KIRAN

See here.. Order is not on PK Name, its my custom order...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-09 : 13:09:41
What determines the customised order in which you want the result?
Go to Top of Page

forum.nasum
Starting Member

4 Posts

Posted - 2008-04-09 : 13:16:24
I can give that... I will give based on PK - I can give the squence of order ..

like Order by PK (1,2,4,..) like this..
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-09 : 13:25:02
You cant give seq like this in order by. I was asking what determines in which order you want output or will the sequence be same always?
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-04-09 : 23:20:19

select table.* from table
inner join
(
select 1 as pk, 1 as orderBy union all
select 5, 2 union all
select 2, 3 union all
select 4, 4
)
s on (table.pk=s.pk)
order by s.orderBy

or you can create the sort order table as a real table, or you can add sequence number to your table.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-10 : 04:46:50
or

order by case when value='somevalue' then 1 when value='othervalue' 2.... end,value

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -