Solved

Where..IN..

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

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 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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

808 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