Solved

Select id's from string - dynamic

Posted on 2014-04-15
1
210 Views
Last Modified: 2014-04-15
Hello,

Can I select specific rows from a table using a string? The items in the string are sent into a stored procedure and can contain various id's and I do not how many.
For example here are Id=1 and Id=3

DECLARE @MyString varchar(500)='1,3'

It could also be Id=1, Id=3 and Id=4
DECLARE @MyString varchar(500)='1,3,4'

DECLARE @MyTable table(Id int,MyString varchar(50))
INSERT INTO @MyTable(Id,MyString)values(1,'One')
INSERT INTO @MyTable(Id,MyString)values(2,'Two')
INSERT INTO @MyTable(Id,MyString)values(3,'Three')
INSERT INTO @MyTable(Id,MyString)values(4,'Four')
INSERT INTO @MyTable(Id,MyString)values(5,'Five')
0
Comment
Question by:johnson1
[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
1 Comment
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 40001400
This article by Angeliii should help:
http://www.experts-exchange.com/Database/Miscellaneous/A_1536-delimited-list-as-parameter-what-are-the-options.html

It provides options for using a delimited parameter.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

759 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