Solved

How Do You Pass In Multiselect Parameters Into a Stored Procedure?

Posted on 2016-08-05
5
48 Views
Last Modified: 2016-08-08
How Do You Pass In Multi-select parameters into a Stored Procedure?  

I need the results to be in a @LOB_KEY

the code:
		HAVING 	CLAIM_LAST_STATUS IN (@CLAIM_STATUS) 
			AND LOB_KEY IN (@LOB_KEY) 
			AND POLICY_YR IN (@POLICY_YR)

Open in new window


The @LOB_KEY needs to be passed in and partitioned into multiple values:
HAVING IN (value1, value2 etc..) CLAUSE

Any advice on a solution is appreciated.

Dan
0
Comment
Question by:danielolorenz
5 Comments
 
LVL 26

Assisted Solution

by:Shaun Kline
Shaun Kline earned 125 total points
ID: 41744766
0
 

Author Comment

by:danielolorenz
ID: 41744814
Here is my code:

declare @names varchar(200);

set @names = 'Dan, Dirk';

SELECT TOP 1000 [USER_KEY]
      ,[SECURITY_ID]
      ,[USER_FIRST_NM]
      ,[USER_LAST_NM]
      ,[USER_EMAIL]
      ,[ACTIVE_IND]
  FROM [BRAC_Portal].[dbo].[PORTAL_USER]
  where [USER_FIRST_NM] IN ('' + @names + '')

Open in new window


How do you get this code to work?  What is the best syntax?

Dan
0
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 125 total points
ID: 41744848
Create a user-defined table type, and pass the values into the proc as a table.  That is the modern approach to this issue.
0
 
LVL 41

Accepted Solution

by:
Sharath earned 250 total points
ID: 41744984
try this.
declare @names varchar(200);

set @names = 'Dan, Dirk';

SELECT TOP 1000 [USER_KEY]
      ,[SECURITY_ID]
      ,[USER_FIRST_NM]
      ,[USER_LAST_NM]
      ,[USER_EMAIL]
      ,[ACTIVE_IND]
  FROM [BRAC_Portal].[dbo].[PORTAL_USER]
  where [USER_FIRST_NM] IN (
  SELECT ltrim(SUBSTRING(names, n, CHARINDEX(',', names + ',',n) - n))
 FROM (SELECT @names names) t1
CROSS JOIN (SELECT number FROM master..spt_values WHERE type = 'P')  AS Numbers(n)
WHERE SUBSTRING(',' + names, n, 1) = ','
  AND n < LEN(names) + 1)

Open in new window

0
 

Author Closing Comment

by:danielolorenz
ID: 41747712
Excellent help.  Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Job Hung 17 35
Rebooting Witness SQL Server 2 23
SQL Throw Error 7 31
Logical Operator should return Integer value in SSIS 9 34
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question