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

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 3195
"Kevin Chambers" <KB********@gmail.comwrote in message
<11**********************@i15g2000cwa.googlegroups .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********@gmail.comwrote in message
<11**********************@i15g2000cwa.googlegroups .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!aform.txtstring, Field1) 0

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

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

"," & Forms!aform.txtstring & "," 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********@gmail.comwrote in message
<11**********************@i15g2000cwa.googlegroup s.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
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...
11
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 !! ...
9
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...
5
by: Lyle Avery | last post by:
Hello guys, Look at this in c++ file: class T { public: char c; char ca; };
4
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...
4
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
by: anto frank | last post by:
hi friends, is ther any difference in array in c and array in c++?
1
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.