473,406 Members | 2,710 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,406 software developers and data experts.

Select .... where the Item.ID is in this array?

Hiya,
I want to populate a list view (in a variety of ways), but I would rather
not execute my function once for every record I want to show in the list.
What I want to do is pass an array of "keys" into a stored procedure and
have that procedure return one recordset with all of the records in. So
what I want to do is something like:

CREATE PROCEDURE MySuperProcedure

@MyArrayOfIDs (some way of specifying an array of integers),

AS
SELECT *
FROM MyTable
WHERE MyArrayOfIDs.ContainsTheInteger ( MyTable.ID )
Obviously this syntax is not available. Is there another way of doing this?
Jul 20 '05 #1
3 1634
Something like

Create Procedure MySuperProcedure
@MyArrayOfIDs varchar(8000)
AS
SELECT *
FROM MyTable
WHERE CHARINDEX(convert(varchar, MyTable.MyField) + '', convert(char,
@MyArrayOfIDs)) <> 0
Sample call
EXEC MySuperProcedure '1, 6'

Returns
MyField
-----------
1
6

(2 row(s) affected)

--
Terry Kreft
MVP Microsoft Access
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:cg*******************@news.demon.co.uk...
Hiya,
I want to populate a list view (in a variety of ways), but I would rather
not execute my function once for every record I want to show in the list.
What I want to do is pass an array of "keys" into a stored procedure and
have that procedure return one recordset with all of the records in. So
what I want to do is something like:

CREATE PROCEDURE MySuperProcedure

@MyArrayOfIDs (some way of specifying an array of integers),

AS
SELECT *
FROM MyTable
WHERE MyArrayOfIDs.ContainsTheInteger ( MyTable.ID )
Obviously this syntax is not available. Is there another way of doing this?

Jul 20 '05 #2
Nice one. Thanks very much Terry.

"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:vT********************@karoo.co.uk...
Something like

Create Procedure MySuperProcedure
@MyArrayOfIDs varchar(8000)
AS
SELECT *
FROM MyTable
WHERE CHARINDEX(convert(varchar, MyTable.MyField) + '', convert(char,
@MyArrayOfIDs)) <> 0
Sample call
EXEC MySuperProcedure '1, 6'

Returns
MyField
-----------
1
6

(2 row(s) affected)

--
Terry Kreft
MVP Microsoft Access
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:cg*******************@news.demon.co.uk...
Hiya,
I want to populate a list view (in a variety of ways), but I would rather
not execute my function once for every record I want to show in the list.
What I want to do is pass an array of "keys" into a stored procedure and
have that procedure return one recordset with all of the records in. So
what I want to do is something like:

CREATE PROCEDURE MySuperProcedure

@MyArrayOfIDs (some way of specifying an array of integers),

AS
SELECT *
FROM MyTable
WHERE MyArrayOfIDs.ContainsTheInteger ( MyTable.ID )
Obviously this syntax is not available. Is there another way of doing

this?


Jul 20 '05 #3
Robin Tucker (id*************************@reallyidont.com) writes:
I want to populate a list view (in a variety of ways), but I would rather
not execute my function once for every record I want to show in the list.
What I want to do is pass an array of "keys" into a stored procedure and
have that procedure return one recordset with all of the records in. So
what I want to do is something like:

CREATE PROCEDURE MySuperProcedure

@MyArrayOfIDs (some way of specifying an array of integers),

AS
SELECT *
FROM MyTable
WHERE MyArrayOfIDs.ContainsTheInteger ( MyTable.ID )

Obviously this syntax is not available. Is there another way of doing
this?


While the syntax Terry showed you is likely to work, the performance is
utterly poor when the list grow in size, not the least since it cannot
use any index on the column in question.

Look at http://www.sommarskog.se/arrays-in-s...st-of-integers
for a more efficent solution. (The article presents even more effecient
solutions than this one, but this is the is easiest to use.)
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4

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

Similar topics

8
by: asd | last post by:
I need to find the value/index of the previously selected item of a select list. That is, when the user selects an item from the list and a certain condition elsewhere in the form is not met, I...
2
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it...
5
by: Phill W. | last post by:
(VB'2003) What's the correct way to remove multiple, selected items from a ListView control (say, from a ContextMenu)? I ask because I'm getting a very annoying ArgumentOutOfRangeException...
5
by: Bubba | last post by:
I have a dynamic pulldown list (ASP with javascript) that when a user picks a state, the corresponding counties for that state appear in a dynamic second pulldown list. When I submit the form, the...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.