Solved

Where..IN..

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

13 Experts available now in Live!

Get 1:1 Help Now