• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

WhereClause 'IN' operator as Sproc Parameter

I would like to pass in the 'In' portion of a query to a stored procedure, but I'm having problems.

select * from table where phone IN ('555-5555', '666-6666');

that query correctly returns 2 results.

However, this:

declare @where nvarchar(max);
set @where = '''555-5555'', ''666-6666'''
select * from table where phone IN (@where);

returns nothing.

I suspect I have an error with my escape strings for the single quotes, but I've tried several combinations such as using double quotes with singles inside, etc, but to no avail.

I'm sure there's a simple solution.

Thanks.
0
tradeline
Asked:
tradeline
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
EXEC ('select * from table where phone IN ( ' +@where' ) '  )
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now