I would like to use a parameter in my mssql stored procedures to switch between a small and a detailed result (for maintainability, performance and network load reasons).
If parameter is set to 1 i get all columns, else only the one or two most important. In a very limited way it works like this:
ALTER PROCEDURE [dbo].[GetAllUsers]
@detail BIT
AS
IF @detail = 1 SELECT UserName, Title, UserID FROM Users
ELSE SELECT Username FROM Users
But I want to use a combined WHEN clause. The following is what i tried, but this doesnt work.
ALTER PROCEDURE [dbo].[GetAllUsers]
@detail BIT
AS
CASE @detail
WHEN 1 THEN SELECT UserName, Title, UserID
ELSE SELECT UserName END
FROM Users
WHERE UserID < 5
Is there any way to achieve somehting like that?