I have a stored procedure I want to pass a parameter to. I want to adjust my Select statement based on whether the parameter is null or contains a value. How do I structure the Select case to have a codeblock rather than a simple assignment after the "Then" or "Else"
Select Case isnull(@variable,'null')
when 'null' then select x from table
else select x from table where table.field = @variable
I tried putting into Begin and end but that does not seem to work
Note: This is not a duplicate of the question about using parameters in a stored procedure- it is about a code block in a "case.. when" statement. The usage of the parameter is part of the example, not part of the question