Groups | Blog | Home
all groups > sql server (alternate) > june 2004 >

sql server (alternate) : SQL Syntax problem


Cristian Martinello
6/30/2004 3:05:00 PM
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 ?


--
Mischa Sandberg
6/30/2004 5:08:24 PM
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

[quoted text, click to view]

byronbayer NO[at]SPAM hotmail.com
7/1/2004 3:34:13 AM
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

AddThis Social Bookmark Button