Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unknown number of SELECTS or something....?

Status
Not open for further replies.

palagrim

Programmer
Apr 28, 2005
31
0
0
GB
Hi there,

I'm currently developing an ASP application which pulls personal data out of a MS-SQL server.

I should start by pointing out that I hate SQL. I don't get it and constantly struggle with it. So any help will be gratefully received.

In my table I have something like:

ID | Name | Group | Email | Phone
131 XXXX XXX XX@XX 12345
132 YYYY YYY YY@XX 67890

etc etc..

In the ASP application, users can select multiple people from a Web List. So, I'll potentially end up with

xxx.asp?userIDs=131,132,134.... ad infinitum.

I COULD get the asp to loop through a series of SELECT * from TABLE where ID = x things and store them in an array, but was wondering how to do it all in one hit. While not knowing how many IDs are going to be passed to the stored procedure?

I've googled about, but without knowing SQL at all well, it's hard to track down a solution...

Thanks,
Craig.
 
faq183-3979, faq183-5207...

Typically, you pass comma-separated list of userIDs to stored procedure, it splits string into table variable... the rest is simple.

------
[small]select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')[/small]
[banghead]
 
Thanks man...

I cut n paste the fn_split thing from a link in the first FAQ and ended up with:

select * from Table
join fn_split('1,4', ',') on Table.ID = fn_split.value

And it works...

Nice... I really need to study this sh*t more... ;-)

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top