Discussion Locked

Please help - TSQL Question

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi I really need to know the best way to be allow my stored procedures to be able to receive multiple arguments.

Can this be done with an array?

EG. I have a query where the WHERE clause may be for many 'people' in my database. Or the where clause may just be for 1 person.
If u need more information email at jantkea@progressivebiz.com

5 replies

by hclarius

I don't believe T-SQL supports arrays. Of course multiple arguements are supported.
Checkout the following newsgroup:
microsoft.public.sqlserver.programming

by medievaldude

No, you can't pass an array, but something you could do is pass in one argument, let's call it @people, that could contain one or multiple names. For one name, @people would simply be 'BOB', and for multiple names, @people would be 'BOB', 'CARLA', 'BETTY'

Now, the trick is to set up your query in this way:
SELECT * FROM mytable WHERE name IN (@people)

That statement could look like this to TSQL once @people is filled in:
SELECT * FROM mytable WHERE name IN ('BOB', 'CARLA', 'BETTY')

What this does is grabs all data where the name field is one of those listed in your @people argument, whether it's one person or multiple persons. Make sure you set up @people to be a VARCHAR large enough for your needs. Post a response if you still need more help.

This discussion is closed to new replies.