By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,419 Members | 1,612 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,419 IT Pros & Developers. It's quick & easy.

Using parametrized "IN"

P: 24
dear friends


I have a problem with using "WHERE * IN ( ...... )" in sqlcommand ;

for exp;

Expand|Select|Wrap|Line Numbers
  1. select * from users where id in (1,2) 
  2. // return 2 rows

but occur error when pass the "1,2" with parameters

Expand|Select|Wrap|Line Numbers
  1. declare @id nvarchar(3)
  2. set @id = '1,2'
  3. select * from users where id in (@id)

please help me to find good solution .

thanks
Jul 20 '09 #1
Share this Question
Share on Google+
2 Replies


ck9663
Expert 2.5K+
P: 2,878
Where does your "1,2" value comes from? If it's from a front-end, trying building your query dynamically and use an OR instead.

--- CK
Jul 22 '09 #2

P: 7
hi,

try this

--
USE tempdb
GO

IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'testSP' AND type = 'P')
DROP PROCEDURE testSP

GO

CREATE PROCEDURE testSP
(
@ids varchar(20)
)
AS
BEGIN

DECLARE @prc nvarchar(300)

SET @prc = 'SELECT * FROM Delta d WHERE d.ID IN (' + @ids + ')'

EXEC(@prc)
END
GO

EXEC testSP '1,2'
GO
--

thanks
east7
Jul 23 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.