Solved

Where..IN..

Posted on 2012-03-27
2
222 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
selective rebuild of SQL Tables in scheduled job 10 46
find SQL job run average duration 24 75
When to use a Unique Index? A Clustered Index? 5 75
Estimating my database size 7 51
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, …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 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