J
JJ
When running an sql stored procedure, is it possible to pass in the
sortexpression as a parameter? When I try it all the other parameters
operate as expected, but the rows are not sorted. The paging works ok, but
not the sorting.
JJ
My data layer has something like:
SqlCommand cmd = new SqlCommand("Stored_Proc_Name", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@LowerBound", SqlDbType.Int).Value = lowerBound;
cmd.Parameters.Add("@UpperBound", SqlDbType.Int).Value = upperBound;
cmd.Parameters.Add("@SortExpression", SqlDbType.NVarChar).Value =
sortExpression;
cn.Open();
The SQL stored proc would be something like:
SELECT * FROM(
SELECT
...Table rows....
ROW_NUMBER() OVER (ORDER BY @SortExpression DESC) AS RowNum
FROM
...TheTable...
WHERE
....SelectionCriteria...
) AllRows
WHERE AllRows.RowNum BETWEEN @LowerBound AND @UpperBound
ORDER BY RowNum ASC
sortexpression as a parameter? When I try it all the other parameters
operate as expected, but the rows are not sorted. The paging works ok, but
not the sorting.
JJ
My data layer has something like:
SqlCommand cmd = new SqlCommand("Stored_Proc_Name", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@LowerBound", SqlDbType.Int).Value = lowerBound;
cmd.Parameters.Add("@UpperBound", SqlDbType.Int).Value = upperBound;
cmd.Parameters.Add("@SortExpression", SqlDbType.NVarChar).Value =
sortExpression;
cn.Open();
The SQL stored proc would be something like:
SELECT * FROM(
SELECT
...Table rows....
ROW_NUMBER() OVER (ORDER BY @SortExpression DESC) AS RowNum
FROM
...TheTable...
WHERE
....SelectionCriteria...
) AllRows
WHERE AllRows.RowNum BETWEEN @LowerBound AND @UpperBound
ORDER BY RowNum ASC