We help IT Professionals succeed at work.
Get Started

SSRS Specifc Sort Order

normajm400
normajm400 asked
on
778 Views
Last Modified: 2012-05-12
Hello,

I'm new to working with SQL, SSRS and Report Builder - Access is my area of experience.  In my first Tablix I need to set up quarters and then months in a specific order - August through July.
I've got everything working except when Q2 is expanded and it doesn't show the months in the order needed

+Q2
November

-Q2
January|November|December

Quarter code:
  ,Case 
	When DatePart(month,[Posting Date]) in (8,9,10) then 'Q1'
	When DatePart(month,[Posting Date]) in (11,12,1) then 'Q2'
	When DatePart(month,[Posting Date]) in (2,3,4) then 'Q3'
	Else 'Q4'
End As 'Quarter'

Open in new window


Order by code:
ORDER BY (CASE WHEN 'MonthVal' = 2 THEN 0 
	When 'MonthVal' = 3 then 1
	When 'MonthVal' = 4 then 2
	When 'MonthVal' = 5 then 3
	When 'MonthVal' = 6 then 4
	When 'MonthVal' = 7 then 5
	When 'MonthVal' = 8 then 6
	When 'MonthVal' = 9 then 7
	When 'MonthVal' = 10 then 8
	When 'MonthVal' = 11 then 9
	When 'MonthVal' = 12 then 10
	When 'MonthVal' = 1 then 11 END)

Open in new window


When I try to add the following code to Order by
,(CASE WHEN 'Month Name' LIKE 'February' then 0
	When 'Month Name' LIKE 'March' then 1
	When 'Month Name' LIKE 'April' then 2
	When 'Month Name' LIKE 'May' then 3
	When 'Month Name' LIKE 'June' then 4
	When 'Month Name' LIKE 'July' then 5
	When 'Month Name' LIKE 'August' then 6
	When 'Month Name' LIKE 'September' then 7
	When 'Month Name' LIKE 'October' then 8
	When 'Month Name' LIKE 'November' then 9
	When 'Month Name' LIKE 'December' then 10
	When 'Month Name' LIKE 'January' then 11 END)

Open in new window


I get the following error: A constant expression was encountered in the ORDER BY list, position 2.

I know I should set this up as a function or something similar so I can reuse it, but I would like to get this working just for this first report.

Suggestions please...

Thank you.
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE