473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Using parametrized "IN"

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
2 1502
ck9663
2,878 Expert 2GB
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
east7
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

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

Similar topics

1
by: Bernd Hohmann | last post by:
I have a question about using "*" in (sub)queries. This example query counts the number of records for a certain customer starting with record "80172" and stops after 10 rows. SELECT...
14
by: mike | last post by:
I'm using postgresl 7.3.2 and have a query that executes very slowly. There are 2 tables: Item and LogEvent. ItemID (an int4) is the primary key of Item, and is also a field in LogEvent. Some...
1
by: Newish | last post by:
Hi Is it really not recommended to us Eval in databound controls as follows: <td><asp:TextBox id="BookTitle" Runat="Server" Text='<%# Eval("BookTitle") %>' Font-Size="8pt"...
25
by: samjnaa | last post by:
Please check for sanity and approve for posting at python-dev. In Visual Basic there is the keyword "with" which allows an object- name to be declared as governing the following statements. For...
2
by: santoshsri | last post by:
Hello, Is there any by which I can write a SQL to get the 4th largest salary from a table without using "join" and without using "where" clause. Suppose the table is having two columns :...
1
by: aiyaonline | last post by:
I like to know if the following makes any performance issue. select field_1 from table_1 where country ='USA'; (or) select field_1 from table_1 where country in ('USA'); The reason behind is:...
4
by: fran7 | last post by:
Hi, from help in the javascript forum I found the error in some code but need help. This bit of code works perfectly, trouble is I am writing it to a javascript function so the height needs to be in...
350
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use...
4
by: assgar | last post by:
Hi I would like to put a list of ids in an array and loop to select data from a table using "IN" in the where clause. I am not having any success getting this to work. Any suggestions?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.