Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Select id's from string - dynamic

Posted on 2014-04-15
1
Medium Priority
?
213 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 27

Accepted Solution

by:
Shaun Kline earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

664 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