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
 General SQL Server Forums
 New to SQL Server Programming
 Why would this Order by not work?

Author  Topic 

Adam West
Constraint Violating Yak Guru

261 Posts

Posted - 2009-07-27 : 16:53:11
SELECT *
FROM Vw_Details
Where ReportMonth = @ReportMonth and (ReportYear = @ReportYear or ReportYear = @ReportYear-1)
and CustName = @CustName ORder by ReportYear
Order by "UserCatLongDescr_CATS"

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-07-27 : 17:00:47
Well there are two ORDER BY clauses.. does this work?
SELECT 
*
FROM
Vw_Details
Where
ReportMonth = @ReportMonth
and (ReportYear = @ReportYear or ReportYear = @ReportYear-1)
and CustName = @CustName
ORDER BY
ReportYear,
UserCatLongDescr_CATS
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-27 : 17:01:40
Drop the double quotes. And don't use double ORDER BY.
Separate them with comma.

SELECT *
FROM Vw_Details
Where ReportMonth = @ReportMonth
and ReportYear IN (@ReportYear, @ReportYear-1)
and CustName = @CustName
ORder by ReportYear, UserCatLongDescr_CATS



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-27 : 17:02:01



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

sajeev4evr
Starting Member

5 Posts

Posted - 2009-08-07 : 06:57:42
Nice
Go to Top of Page
   

- Advertisement -