I have a select which needs to have dynamic WHERE CASE conditions.
SELECT
*
FROM
vwShowUctyPohyby
WHERE
(@id_parent is null or id_parent=@id_parent)
and (datetime_creation <= @record_first_datetime)
ORDER BY
CASE @sort_order WHEN 0 THEN datetime_creation END ASC,
CASE @sort_order WHEN 1 THEN datetime_creation END DESC
As you can see there is a condition to dynamically choose type of ORDER. Now I need to do same with WHERE part. I found that it can work like datetime_creation = CASE ….. WHEN … THEN …. END.
Problem is that I need to create datetime_creation <= @record_first_datetime for one WHERE condition and datetime_creation >= @record_first_datetime for other condition.
How do I do that? I dont want to create two selects and use IF ELSE statement.
I am using this SELECT for dynamic paging on SQL side, with ROWCOUNT.
Is this your intention ?