473,769 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array to "IN" operator

Hi all--

Quick question: has anyone come up with an easy way to take an array
and use its elements as part of a WHERE clause? For example:
<This obviously doesn't work>
SELECT *
FROM Table1
WHERE Field1 IN Array(1,2,3)

The only solution I can think of is putting the values in a temp table
and then doing this:
SELECT *
FROM Table1
WHERE Field1 IN (SELECT Val FROM TTable)

But it would be nice to not have to go through all that.

Thoughts?

Thanks in advance,
KC

Jan 4 '07 #1
3 3242
"Kevin Chambers" <KB********@gma il.comwrote in message
<11************ **********@i15g 2000cwa.googleg roups.com>:
Hi all--

Quick question: has anyone come up with an easy way to take an array
and use its elements as part of a WHERE clause? For example:
<This obviously doesn't work>
SELECT *
FROM Table1
WHERE Field1 IN Array(1,2,3)

The only solution I can think of is putting the values in a temp
table and then doing this:
SELECT *
FROM Table1
WHERE Field1 IN (SELECT Val FROM TTable)

But it would be nice to not have to go through all that.

Thoughts?

Thanks in advance,
KC
Doesn't this work for numbers?

SELECT *
FROM Table1
WHERE Field1 IN (1,2,3)

and this for text?

WHERE Field1 IN ('1','2','3')

If you mean stuff it from a (string) array in VB

....WHERE Field1 IN (" & join(myarray, ",") & ")"

--
Roy-Vidar
Jan 4 '07 #2
Yes, that would certainly work to concatenate a SQL string like that,
and use that as the basis for creating a recordset. I was more
wondering about something I could pass in to a saved Access query
object via parameters or a function that returns an array. If I used
join(array()) as a parameter, the query would take the entire string
and evaluate as one value, ie, Field1 = '''1'',''2'','' 3'''.

It seems like the only solution is to do it the way you describe or go
with a temp table.

Unless there are any other bright ideas?

RoyVidar wrote:
"Kevin Chambers" <KB********@gma il.comwrote in message
<11************ **********@i15g 2000cwa.googleg roups.com>:
Hi all--

Quick question: has anyone come up with an easy way to take an array
and use its elements as part of a WHERE clause? For example:
<This obviously doesn't work>
SELECT *
FROM Table1
WHERE Field1 IN Array(1,2,3)

The only solution I can think of is putting the values in a temp
table and then doing this:
SELECT *
FROM Table1
WHERE Field1 IN (SELECT Val FROM TTable)

But it would be nice to not have to go through all that.

Thoughts?

Thanks in advance,
KC

Doesn't this work for numbers?

SELECT *
FROM Table1
WHERE Field1 IN (1,2,3)

and this for text?

WHERE Field1 IN ('1','2','3')

If you mean stuff it from a (string) array in VB

...WHERE Field1 IN (" & join(myarray, ",") & ")"

--
Roy-Vidar
Jan 5 '07 #3
It won't be any too quick, but for simple list of one digit
items in the list you could use a calculated field in the
query (with its Show box unchecked):

InStr(Forms!afo rm.txtstring, Field1) 0

Or if any value in the field might match just a part of any
item in the list:

InStr("," & Forms!aform.txt string & ",", "," & Field1 & ",")
0
If the field can not contain any wildcard characters, you
could also use Like instead of Instr:

"," & Forms!aform.txt string & "," Like "*," & Field1 & ",*"

aform is an open form and txtstring is a text box on the
form where you have parked the results of the Join function.
--
Marsh
Kevin Chambers wrote:
>Yes, that would certainly work to concatenate a SQL string like that,
and use that as the basis for creating a recordset. I was more
wondering about something I could pass in to a saved Access query
object via parameters or a function that returns an array. If I used
join(array() ) as a parameter, the query would take the entire string
and evaluate as one value, ie, Field1 = '''1'',''2'','' 3'''.

It seems like the only solution is to do it the way you describe or go
with a temp table.

Unless there are any other bright ideas?

RoyVidar wrote:
>"Kevin Chambers" <KB********@gma il.comwrote in message
<11*********** ***********@i15 g2000cwa.google groups.com>:
Hi all--

Quick question: has anyone come up with an easy way to take an array
and use its elements as part of a WHERE clause? For example:
<This obviously doesn't work>
SELECT *
FROM Table1
WHERE Field1 IN Array(1,2,3)

The only solution I can think of is putting the values in a temp
table and then doing this:
SELECT *
FROM Table1
WHERE Field1 IN (SELECT Val FROM TTable)

But it would be nice to not have to go through all that.

Thoughts?

Thanks in advance,
KC

Doesn't this work for numbers?

SELECT *
FROM Table1
WHERE Field1 IN (1,2,3)

and this for text?

WHERE Field1 IN ('1','2','3')

If you mean stuff it from a (string) array in VB

...WHERE Field1 IN (" & join(myarray, ",") & ")"

--
Roy-Vidar
Jan 5 '07 #4

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

Similar topics

2
1485
by: Rick Francis | last post by:
I need help serializing an array without including the array "name". I am writing in C# and using the XmlSerializer to serial classes. I am trying to serialize a class with an array in it like the one below. public class myclass { public imagecontext; public myimage images; }
11
2702
by: fourfires.d | last post by:
Dear All, I am new to c++ and when write below code that try to call copy constructor in "=" operator overloading, it can not compile. Can anyone point out for me the reason? thanks !! class AA {
9
2199
by: Emanuele Aina | last post by:
I have some code which does a lot of "in" on lists containing objects with no __eq__ defined. It all goes fast until I add the __lt__() method: then I have a slowdown comparable to the one I get using the overridden __eq__, while the __lt__ method is never called. Someone can explain me why?
5
4749
by: Lyle Avery | last post by:
Hello guys, Look at this in c++ file: class T { public: char c; char ca; };
4
1576
by: pradeep kaltari | last post by:
Hello friends, I have a doubt in the working of IN operator. I have a schema by name 'test_schema'. If you look at the following query the expected output is "1", but nothing is displayed. SELECT 1 FROM TABLE1 WHERE UPPER( 'test_schema' ) IN ( SELECT UPPER(SCHEMA_NAME) FROM INFORMATION_SCHEMA.SCHEMATA
4
1398
by: devphylosoff | last post by:
hi i have class array, and operator= : I remove ..... template <typename T2array<Toperator= (const array<T2rhs) { if (this != &rhs) { resize(rhs.size());
45
7394
by: anto frank | last post by:
hi friends, is ther any difference in array in c and array in c++?
1
1499
by: =?Utf-8?B?U3RlZmFuIFNvbGplbW8=?= | last post by:
I trying to add objects to an array without success. The array is declared as A** arr**. It is allocated with with the new operator. Two instances of the class A is allready instanciated with the new operator and assigned to the array with the brackets as shown below. The problem is that both elements in the array is assigned the first obejct Test1. Note that the main class is managed. Im using Microsoft Visual Studio 2008. Thanks on...
2
2164
by: susheela s | last post by:
i wrote a program to add bytes in array in such a way that when i add zeroth byte of two array sum should retained and carry must be added to next addition of bytes(ie array index 1 bytes) this is program which i wrote using class #include<iostream.h> #define N 2 typedef unsigned char byte; class Megaint { private:
0
9422
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10208
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10038
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9857
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8867
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5294
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.