I want the where statement for this query to be optional depending on what the value of parameter @RetrieveAll is. If @RetrieveAll is false/null the where statement is used, if it is true it should be ignored.
@IncludeErrors bit = 1,
@IncludeAccess bit = 1,
@IncludeLogins bit = 1,
@RetrieveAll bit = NULL
SELECT
//...
FROM
(
) AS a
WHERE
a.RowNumber BETWEEN @ItemCountStart AND @ItemCountEnd
Is there way to do this?