Query works and sorts as it should. But query errors when part of ssrs dataset. Errors narrowed down to order by case expressions as shown. Syntax is accepted. First error message during run: "An error has occurred during report processing. (rsProcessingAborted)" The Details>> button for the error popup shows the try n errors below.
select <columns>
from <view>
where <criteria>
order by
> error condition - try 1
-- errors "The isnull function requires 2 argument(s)."
case when isnull(<parm>, '') <> ''
then <column to be sorted>
end,
> error condition - try 2
-- errors "An expression of non-boolean type specified in a context where a condition is expected, near ..."
case when (<parm> is not null or
<parm> <> '')
then <column to be sorted>
end,
> error condition - try 3
-- errors "An expression of non-boolean type specified in a context where a condition is expected, near ..."
case when <parm> is not null
then <column to be sorted>
when <parm> <> ''
then <column to be sorted>
end,
<more columns to sort>