I writing a SP that accepts as parameters column to sort and direction.
I don't want to use dynamic SQL.
The problem is with setting the direction parameter.
This is the partial code:
SET @OrderByColumn = 'AddedDate'
SET @OrderDirection=1;
.
.
.
ORDER BY
CASE WHEN @OrderByColumn='AddedDate' THEN CONVERT(varchar(50),AddedDate)
WHEN @OrderByColumn='Visible' THEN CONVERT(varchar(2), Visible)
WHEN @OrderByColumn='AddedBy' THEN AddedBy
WHEN @OrderByColumn='Title' THEN Title
END