Click to See Complete Forum and Search --> : SELECT Statement based on an array of values


hdogg
08-14-2007, 09:27 AM
I create the array userid[]

usersid[1] = 1231
usersid[2] = 455
usersid[3] = 1251
usersid[4] = 1291

The array is populated by form check box's submitted.

I want to SELECT items from a database with those userid's

SELECT USER_ID FROM USERS WHERE USERID = "userid"

How do I get that to work?

NogDog
08-14-2007, 11:10 AM
$query = "SELECT user_id FROM users WHERE userid IN(" . implode(',', $userid) . ")";

Nandem
08-14-2007, 11:16 AM
You have to make an function that returns an table type,
and, in that function make an algorithm to make your varchar array
splitting manually to a table that u will return....

nothing impossible to do....

and, and use a return table from your function like that...


--@USERID = parameter varchar(8000) from caller.
--@Separator = You can choose one, like '#', or '$', or ','... with space or not... you decide on your function

SELECT USER_ID FROM USERS WHERE USERID IN (SELECT DataColumn FROM dbo.MySplitFunction(@UserID, @Separator))