Solved

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

Posted on 2016-08-05
5
54 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.

623 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