Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hello,I'm new to SQL Server 2005. I'm migrating from Access/Jet and having trouble with this sort:
SELECT A,B,C FROM ... WHERE ... ORDER BY (A/B) DESC;
It worked fine with Access but is ignored by SQL Server.I have already tried this without luck:
SELECT A,B,C, (A/B) AS mysort FROM ... WHERE ... ORDER BY mysort DESC;
I'm using SQLNCLI if that matters.Any idea ? Thank you.
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2007-07-29 : 04:52:43
[code]SELECT A,B,C FROM ... WHERE ... ORDER BY (A/B) DESC[/code]This will work in SQL Server 2005.What is the data type of column A and B ? Is it integer ?Do take note that integer divide by integer will give you integer. Which means select 1 / 2 will give you 0KH[spoiler]Time is always against us[/spoiler]
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2007-07-29 : 04:56:22
SELECT A,B,C FROM ... WHERE ... ORDER BY 1.0 * A / B DESCE 12°55'05.25"N 56°04'39.16"
bienew
Starting Member
8 Posts
Posted - 2007-07-29 : 04:59:17
Yes they are both integers. Adding 1.0 as per peso suggestion works fine.So that was the reason. Thanks a lot !!
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2007-07-29 : 05:04:05
Or you could try SELECT A,B,C FROM ... WHERE ... ORDER BY A * B ASCjust for fun...E 12°55'05.25"N 56°04'39.16"