?
Solved

Where..IN..

Posted on 2012-03-27
2
Medium Priority
?
225 Views
Last Modified: 2012-03-28
Hello all
I have this query
DECLARE @a nvarchar(50)
SET @a = '1,3'

select * 
from tableName 
where CAST(ColumnId as nvarchar(50)) in (@a)

Open in new window

which doesn't work.
i would like it to work like the following query
select * 
from tableName 
where ColumnId in (1,3)

Open in new window

please advice
Thank's
0
Comment
Question by:contel
[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
2 Comments
 

Accepted Solution

by:
contel earned 0 total points
ID: 37775320
Hi,
I've Tried with two diffrenet integer parameters if your columnID is integer. its working.

DECLARE @1 int
DECLARE @2 int
SET @1 = 1
SET @2 = 3

select * 
from tableName 
where ColumnId in (@1, @2)

Open in new window

0
 
LVL 5

Expert Comment

by:Ronak Patel
ID: 37775331
DECLARE @a nvarchar (50)
SET @a = '1,3'

DECLARE @SQL nvarchar (2000)

SET @SQL = 'SELECT * FROM  tableName WHERE CAST(columnId as nvarchar(50)) IN (' + @a + ')'

execute(@SQL)

Open in new window

0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

764 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