Solved

Where..IN..

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

719 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