April 23, 2012 at 9:27 am
I know there's several ways to sort data when multiple fields are used. However, I'm taking a different path that I'm not used to.
I'm wokring on a report that gives the user the selection of two different sorts. In these two sorts, each sort is sorted with multiple fields. To know what I'm talking about, here's the Order By I'm trying to use and with this, I'm getting an error and dont understand why. Hope someone here can assist.
Thanks.
ORDER BY CASE
WHEN @SortBy = 'A' THEN [CASE ID], [CONTACT ALPHA], [SCHEDULED PRIORITY], [CONTACT ALPHA]
WHEN @SortBy = 'P' THEN [CASE ID], [SCHEDULED PRIORITY], [CONTACT ALPHA]
END
April 23, 2012 at 9:47 am
Hi,
Don't think you can reference multiple fields in one case statement - you'll need a case statement per order by field:
ORDER BY [CASE ID],
CASE
WHEN @SortBy = 'A' THEN [CONTACT ALPHA]
WHEN @SortBy = 'P' THEN [SCHEDULED PRIORITY]
END,
CASE
WHEN @SortBy = 'A' THEN [SCHEDULED PRIORITY]
WHEN @SortBy = 'P' THEN [CONTACT ALPHA]
END,
etc
Cheers
April 23, 2012 at 9:57 am
Thanks. That worked. I knew I was over thinking it.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply