I have a stored procedure which uses dynamic sorting, 2 parameters determine the sorting - column: @SortIndex and sort direction: @SortDirection
relevant code:
...
ROW_NUMBER() OVER
(
ORDER BY
-- string order by
CASE @SortDirection
WHEN 'ASC' THEN
CASE @SortIndex
WHEN 1 THEN SKU
WHEN 2 THEN BrandName
WHEN 3 THEN ItemName
END
END ASC,
CASE @SortDirection
WHEN 'DESC' THEN
CASE @SortIndex
WHEN 1 THEN SKU
WHEN 2 THEN BrandName
WHEN 3 THEN ItemName
END
END DESC,
This sorts on single columns, but I want to sort on BrandName ASC, ItemName ASC when @SortIndex is 2.
WHEN 2 THEN BrandName + ',' + ItemNameand it worked. If you want to flesh out your comment & add it as an answer I'll mark it as correct.