Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a team group parameter in my SSMS stored procedure. The team group parameter has 4 values. So far this is what I've coded:

SQL
Declare
 @Param1 int = 1
,@Param2 varchar(4) = '1169'
,@TeamGroup varchar(150) = 'RCBE,RLEG,RPEN,RSPC'

-- Code below supports multi-select in report

if OBJECT_ID('Tempdb..#TeamGroups','U') is not null
   drop table #TeamGroups
CREATE TABLE #TeamGroups
(TeamGroupKey varchar(100))
INSERT INTO #TeamGroups
SELECT value FROM HEA.Parselist(@TeamGroup,',')


I later join my #Teamgroups table to my main query. My question then: is it possible to use a case statement when I create my Temp table, so that I can include a select all or exclude all value? Or should I approach this differently?

What I have tried:

I've researched MSDN parameters as well as how to modify them.
Posted
Updated 23-Feb-16 6:30am

1 solution

There are many ways to do it; however, one easy way would be to do something like this:
SQL
SELECT value FROM HEA.Parselist(@TeamGroup, ',')
UNION 
SELECT team
FROM TeamGroups
WHERE @TeamGroup = 'All'


That would union in all your teams if @TeamGroup was a keyword of "All"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900