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 2000 Forums
 SQL Server Development (2000)
 Order by Query

Author  Topic 

ranjeetsingh_6
Posting Yak Master

125 Posts

Posted - 2007-05-07 : 03:39:45
Hi

i want records nither Assending nor Decending order.I want in that order which is exist in query.For example of given query i want output as below
Query:-

SELECT txtgr_no
FROM tbltGR
WHERE txtgr_no IN ('139198', '139194', '139197', '139195', '139196')

My Desire OUTPUT(As it is order which given in query):-

txtgr_no
--------------------
139198
139194
139197
139195
139196




Ranjeet Kumar Singh

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-07 : 03:46:18
[code]SELECT txtgr_no
FROM tbltGR g
Join
(
Select '139198' as txtgr_no, 1 as rank union all
Select '139194', 2 union all
Select '139197', 3 union all
Select '139195', 4 union all
Select '139196', 5
) t
on g.txtgr_no = t.txtgr_no
order by t.rank[/code]

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-07 : 03:58:47
SELECT txtgr_no
FROM tbltGR
WHERE txtgr_no IN (139198, 139194, 139197, 139195, 139196)
order by txtgr_no % 4 + txtgr_no % 5 + txtgr_no % 8 DESC,
txtgr_no % 23 DESC


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

ranjeetsingh_6
Posting Yak Master

125 Posts

Posted - 2007-05-07 : 03:59:42
Thanks to You.

Ranjeet Kumar Singh
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2007-05-07 : 04:10:24
[code]
order by txtgr_no % 4 + txtgr_no % 5 + txtgr_no % 8 DESC,
txtgr_no % 23 DESC
[/code]

This is somthing new to me, what is the logic of this??

Chirag

http://chirikworld.blogspot.com/
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-07 : 04:14:51
None. But it fits the original question.
I can't see the reason to have the records returned in that fashion. If the poster already knows which records to fetch, he would know in which order to sort them at client (front end) application.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2007-05-07 : 04:21:44
Aha.. I See.. but i beliave this is not the first post with this kind of requirement..!!

Chirag

http://chirikworld.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-07 : 08:49:27
quote:
Originally posted by Peso

None. But it fits the original question.
I can't see the reason to have the records returned in that fashion. If the poster already knows which records to fetch, he would know in which order to sort them at client (front end) application.


Peter Larsson
Helsingborg, Sweden


Will that fit to all data?

Madhivanan

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

- Advertisement -