Solved

Select id's from string - dynamic

Posted on 2014-04-15
1
203 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
1 Comment
 
LVL 25

Accepted Solution

by:
Shaun Kline earned 500 total points
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now