473,396 Members | 1,996 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,396 software developers and data experts.

Passing array of numbers to SQL query

I am using an objectdatasource with a .Net 2.0 ASP page.

The SQL for the tableadapter needs to use the IN operator as in
WHERE job_id in (111, 222, 333, 444, 555)
Job_id is a DBType Decimal and ProviderType Number

I have set the default value for the parameter to be
19620,19610,19580,19550 for testing

However, .Net strips the , and turns it into one large number.

How do I specify that it is rather an array or list of numbers,
esentially passing an array of numbers to the parameter?

Sep 9 '06 #1
3 7572
Hi,

The short answer is... you can't. There is no SQL mechanism for passing an
array for use with IN (...).

If the number of list of numbers is small you could just do each element as
a specific parameter. If the list is large you'll have to store the values
in a table and change the IN (...) to be "N ((SELECT n FROM t WHERE
....))"... or maybe an INNER JOIN (once the numbers are stored in a table...
why not do a join instead of an IN).

Regards,

Rob MacFadyen
<jr********@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
>I am using an objectdatasource with a .Net 2.0 ASP page.

The SQL for the tableadapter needs to use the IN operator as in
WHERE job_id in (111, 222, 333, 444, 555)
Job_id is a DBType Decimal and ProviderType Number

I have set the default value for the parameter to be
19620,19610,19580,19550 for testing

However, .Net strips the , and turns it into one large number.

How do I specify that it is rather an array or list of numbers,
esentially passing an array of numbers to the parameter?

Sep 9 '06 #2
jr********@gmail.com wrote:
The SQL for the tableadapter needs to use the IN operator as in
WHERE job_id in (111, 222, 333, 444, 555)

How do I specify that it is rather an array or list of numbers,
esentially passing an array of numbers to the parameter?
Pass it as a string. Then let the stored procedure that returns the data,
parse out the individual items.
There are some issues with this approach....

Search google groups in comp.databases.ms-sqlserver. I remember Erland
Sommarskog (or something like that) has a HP about this specific problem.

/jim
Sep 11 '06 #3
You'll have to pass the list of Integers to the stored procedure as a
string, then handle them on that side.

The quick and dirty way would be to use dynamic sql to build and
execute your query as a big string, but then you'd have to spend the
rest of your career living in fear that some junior dev will dig up
your hacky code one day and call you on it.

What you'll probably end up doing is building a User Defined Function
in the database that takes your comma-separated list and hands it back
as single-column table that you can join into your query:

WHERE job_id in (select value from dbo.inline_list_split(@integerList)
)

Dig around in the SQL groups to find code to do the splitting for you.

Good luck!

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

---
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/
jr********@gmail.com wrote:
I am using an objectdatasource with a .Net 2.0 ASP page.

The SQL for the tableadapter needs to use the IN operator as in
WHERE job_id in (111, 222, 333, 444, 555)
Job_id is a DBType Decimal and ProviderType Number

I have set the default value for the parameter to be
19620,19610,19580,19550 for testing

However, .Net strips the , and turns it into one large number.

How do I specify that it is rather an array or list of numbers,
esentially passing an array of numbers to the parameter?
Sep 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
5
by: Eric A. Forgy | last post by:
Hello, I am just learning Java and am trying to write a method that does something like //=========================================== public Static List find(double array,double val,String...
6
by: supercomputer | last post by:
I am using this function to parse data I have stored in an array. This is what the array looks like: , , , , , , , , , , , , , , , , , , , , , , , ] This is the code to parse the array:
10
by: Resant | last post by:
I have a query : Exec 'Select * From Receiving Where Code In (' + @pCode + ')' @pCode will contain more than one string parameter, eg : A1, A2, A3 How can i write that parameters, I try use :...
3
by: Albert Albani | last post by:
Hello I have a problem that I cannot seem to solve I have a c funtion in a DLL that basically looks like func_c (some_struct* s) {...} some_struct is defined like so: struct some_struct {
6
by: JackM | last post by:
I have a multiple select input in a form that's being populated by a row from my database as such: <input type=\"checkbox\" name=\"subm\" value=\"$row\"> That part is working fine as I can check...
14
by: Peter Hallett | last post by:
I would like to set up a string array as a class member, or field, and then populate this array by reading in from a text file, but I cannot find the appropriate syntax. The getter and setter are...
6
by: hinksta | last post by:
I'm trying to build a football leage table taking it's content from a results database, CREATE TABLE conference ( id int NOT NULL auto_increment primary key, season VARCHAR(50) NOT NULL, ...
3
by: alexmason86 | last post by:
getting a bit stuck here got some code that allows a user to input numbers to a 3x3 array. but next on the tutorial sheet i have to then ask the user for a number to search for and then search the...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.