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
 Transact-SQL (2000)
 Using Between Clause in Order By

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-06-18 : 09:23:53
Umesh writes "Hi,

I have a table A having 2 columns ALow and AHign which store the frequency ranges for a particular row.

I want to Order the Resultset Depending Upon the values present in these columns.

e.g.
ALow AHigh
10 20
21 40
41 60

If i give a number 23 then it should give row2 at the top.

I tried a query in MS-Access which gave me the desired result

Select * From A ORDER BY 23 BETWEEN ALOW and AHIGH

How can i implement same query in SQLSERVER."

Nazim
A custom title

1408 Posts

Posted - 2002-06-18 : 09:45:07
hi there,

you have to use where clause to filter records. Order by is used to sort them.

you may try case statment with order by . Check for "Order by" in Article search.

-------------------------
What lies behind you and what lies ahead of you are small matters compared to what lies within you.-Ralph Waldo Emerson
Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2002-06-18 : 10:12:11
Alternatively, we could answer the question.
Access is somewhat more lax in its dealing with boolean values than SQL Server (and the SQL-92 standard). You need to give SQL Server values it can sort with: usually this involves using a trivial CASE expression with the original boolean expression as the condition. Like this:

Select * From A ORDER BY CASE WHERE 23 BETWEEN ALOW and AHIGH THEN -1 ELSE 0 END


Go to Top of Page
   

- Advertisement -