469,148 Members | 1,390 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,148 developers. It's quick & easy.

SQL Syntax problem

Hi all,
I have a SELECT with a varchar field and a number field.
I need to order by the text field (a,b,c...) for number < 2000, and
another order by for number>0.
The result may look like this:

Aaa 200
bbb 89
ccc 100
aa 2005
bb 2900
cc 2100
....

Is this possible with a single query ?
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
Jul 20 '05 #1
2 1032
Can't figure out what the 'other order' ought to be, from your example, but
....

select * from Table
order by case when number < 2000
then text
else /*something else possibly cast(... as varchar)*/
end

"Cristian Martinello" <ca*********@tiscali.it> wrote in message
news:92*************************************@mygat e.mailgate.org...
Hi all,
I have a SELECT with a varchar field and a number field.
I need to order by the text field (a,b,c...) for number < 2000, and
another order by for number>0.
The result may look like this:

Aaa 200
bbb 89
ccc 100
aa 2005
bb 2900
cc 2100
...

Is this possible with a single query ?
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

Jul 20 '05 #2
Try this.

SELECT Cola, Colb
INTO #Temp1
FROM Table1
WHERE Colb > 2000
ORDER BY Cola
GO
INSERT INTO #Temp1
SELECT Cola, Colb
FROM Table1
WHERE Colb <= 2000
ORDER BY Cola
GO
SELECT * FROM #Temp1
GO
DROP TABLE #Temp1
GO

Jay Freeman
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

699 posts views Thread by mike420 | last post: by
303 posts views Thread by mike420 | last post: by
35 posts views Thread by Moosebumps | last post: by
23 posts views Thread by C. Barnes | last post: by
16 posts views Thread by George Sakkis | last post: by
19 posts views Thread by Nicolas Fleury | last post: by
20 posts views Thread by W Karas | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.