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!

Array in Stored Procedure

Status
Not open for further replies.

vlitim

Programmer
Sep 2, 2000
393
0
0
GB
Is there anything similar in Stored procedures to that of looping through an array in ASP?? ie:

stateID="1,2,3,87"
stateArray = Split(stateID,",")
For i=0 To UBound(stateArray)
//calcs here
Next

Cheers

Tim
 
Unfortunately not. You will have to use a cursor or look carefully at what you want to do. Cursors are not recommended. Where are you getting the data for your array? Post an example of what you want to achieve.
 
Basically I have a form on a page with a multiple select element where the user can choose any number of countries to search on.

so when I get to the results page I have a variable

countryID = "1,3,65"

From there I need to construct annother variable looking Like:

temp = "Partners.countryID=1 OR Partners.countryID=3 OR Partners.countryID=65"

so I can then insert it into an SQL statement. At the moment I am constructing the string on an ASP page and passing it to the stored procedure which is not ideal, and I now need to be able to do it all in the stored procedure!!

Any help or ideas would be most appreciated

Thanks
Tim


 
What u will be passing is a comma seperated string ?

Ans : Using charindex() and substring() in SQL
seperate these values

eg : "1,3,65"

While Looping(seperating) insert into #Country
such that u'r Country table will look as
#Country
Country_id
1
3
65

Now what u can do is use the above as a subquery in the
join
temp in ( Select distinct Country_id from #Country )

Hope that helps



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top