I am looking for a work-around or a solution for a situation where I only want to execute an expression based on two conditions using a CASE statement. I have written some mock pseudo code to illustrate what I am trying to do.
WHERE (RN = 1)
AND
CASE
WHEN (@ApplicationName '' OR @ApplicationGroup '')
THEN
AND (
@AppFilterType = 'Groups' AND [GroupName].[Name] IN (SELECT StringValue FROM [StarTeam].[dbo].fn_CSVToTable(@ApplicationGroup))
OR
@AppFilterType = 'Apps' AND [AppName].[Name] IN (SELECT StringValue FROM [StarTeam].[dbo].fn_CSVToTable(@ApplicationName))
)
END
This is the idea, only execute the condition if @ApplicationName and/or @ApplicationGroup have a value.
I am using this in a T-SQL Stored Procedure running on SQL Server 2005.
Is this possible in some way?
Thanks in advance for any help.
1 Answer