469,579 Members | 1,098 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

SQL In Statement with Variables?

Is it possible to create a SQL In statement using variables?

For example, here is what can be done:

SELECT Test.ID, Test.Desc
FROM Test
WHERE (((Test.ID) In (3,6,9,12)));
But, I would like to do something like this:

SELECT Test.ID, Test.Desc
FROM Test
WHERE (((Test.ID) In ([@TestTypes])));

( I have a loop that will be passing the: 3,6,9,12 )

However, it does not work. Am I missing something in the syntax or is
it I cannot do it this way?

Any thoughts and or advice is greatly appreciated.

Ray

Jun 27 '08 #1
1 2058
You can pass a single parameter easiely - check help for details.

However, for your example it might make more sense to build the sql
statement as a text string and then execute it. Have your loop build
the IN statement and concatenate the parts as required.

Tim Mills-Groninger

On Jun 24, 10:34*am, bcap <r...@patriots.comwrote:
Is it possible to create a SQL In statement using variables?

For example, here is what can be done:

SELECT Test.ID, Test.Desc
FROM Test
WHERE (((Test.ID) In (3,6,9,12)));

But, I would like to do something like this:

SELECT Test.ID, Test.Desc
FROM Test
WHERE (((Test.ID) In ([@TestTypes])));

( I have a loop that will be passing the: 3,6,9,12 )

However, it does not work. *Am I missing something in the syntax or is
it I cannot do it this way?

Any thoughts and or advice is greatly appreciated.

Ray
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by David Hitillambeau | last post: by
5 posts views Thread by Alvin Bruney | last post: by
7 posts views Thread by Sunny | last post: by
35 posts views Thread by Thierry Loiseau | last post: by
13 posts views Thread by eman1000 | last post: by
1 post views Thread by microsoft.public.dotnet.languages.vb | last post: by
2 posts views Thread by franc sutherland | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.