Solved

Sorting in SSRS 2008 using mulitple parameters and depending on a sort by selection

Posted on 2015-01-02
4
57 Views
Last Modified: 2015-06-11
I have a report that has 8 sortby options.  I've pasted the sql code below.

ORDER BY R.CalloutLocation
	 , CASE WHEN @SortBy IN (1,4) THEN CalloutDate
			WHEN @SortBy IN (2,3) THEN R.CalloutReason
			WHEN @SortBy IN (5,6,7,8) THEN R.InstructorName
	   ELSE '0'
	   END ASC
	 , CASE WHEN @SortBy IN (1,3) THEN R.OffenderName
			WHEN @SortBy IN (2,5,8) THEN CalloutDate
			WHEN @SortBy IN (4,6,7) THEN R.CalloutReason
	   ELSE '0'
	   END ASC
	 , CASE WHEN @SortBy IN (3,6) THEN CalloutDate
			WHEN @SortBy IN (4,5,7) THEN R.OffenderName
			WHEN @SortBy = 8 THEN R.CalloutReason
	   ELSE '0'
	   END ASC	
	 , CASE WHEN @SortBy = 7 THEN CalloutDate
			WHEN @SortBy = 8 THEN R.OffenderName
	   ELSE '0' 
	   END ASC

Open in new window



However, when I run the report and select an option, it doesn't sort correctly.  I'd like to try doing the sorting in the report itself.  It currently only groups on the CalloutLocation.  Then there is a detail group below that.  Any help will be greatly appreciated.  Thanks
0
Comment
Question by:Sherry
  • 2
4 Comments
 

Author Comment

by:Sherry
ID: 40528313
Here's the rdl if that will help.
Offender-Attendance-Roster.rdl
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 40528334
The syntax looks the same as what I have in the article SQL Server CASE Solutions (scroll down to 'A typical practice is to pass a parameter to a stored procedure that is the desired sort order'), other than I don't have the ELSE'0' so maybe that's not needed.

Just to check the box, are you certain @SortBy is one of the values in the IN blocks?
0
 

Author Comment

by:Sherry
ID: 40528366
I removed the else '0'  and it seems to be work fine now.  Now all I have to do is figure out why the formatting of the time isn't working like it should.  I have it set for military time HH:mm in the rdl.  The sql has it as

CONVERT(VARCHAR(10), C.StartDateTime, 101) AS CalloutDate

Yet, it still shows the seconds and I can't seem to get rid of it.  Thanks for your help.  I had a feeling it would be something simple.
0
 
LVL 14

Accepted Solution

by:
nishant joshi earned 500 total points
ID: 40560259
Looks like in report,You are using CalloutDateName instead of CallOutDate file from dataset.

Try to use "CalloutDate" Field.


Thanks,
Nishant
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now