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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Recordset based on strong concat? 1

Status
Not open for further replies.

jay123454

Programmer
Jun 15, 2001
46
US
Hi,

Quick question. I usually work in php and I know I can do this in php no problem. But I'd like to do this page in asp so I am hoping someone can help me with my problem.

Here's an example of the problem:

I've got 16 recordsets named:
rs_week1
rs_week2
etc...

I am getting an integer, week, from another recordset...this will be returned as an integer.

I want to contatenate this onto "rs_week" such as
var = "rs_week" & week
so var now equals "rs_week1".

I'll be looping through this over and over so I just want to get the recordset that corresponds to the current week.

Anyone have any ideas how I can get recordset rs_week1 from this dynamically?
 
I think I understand what you're looking for. Try this and see if it helps point you in the right direction (some of the syntax may be off a little in the loop, but the idea should be about right):
Code:
'You already have your integers in a recordset called [b]rsWeek[/b].
i = 1
Do while not rsWeek.EOF
 set rs_week & i = Conn.Execute("SELECT * FROM myTable")
 i = i + 1
 rsWeek.MoveNext
Loop

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Thanks Chopstik,

Sorry, don't think I explained too clearly...you are close.

Assume I already have those recordsets (rs_week1, rs_week2) and in your loop (rs_week) I'd like to access rs_week1, rs_week2 etc...based on which "week" is returned.

I'll just write pseudocode to make it easy to understand.

So say their a recordset rs_getweek

while(rs_getweeek)
{
current_week=rs_getweek->get("week");
//this would return an integer. ex: assume current_week = 1

//Now get the recordset of the week this corresponds to
So I want to get rs_week1 based on the fact I know this is week 1

}

There may be a better way to do this...maybe write a function that passes an integer (week) and returns a proper recordset?

something like

function($week)
{
if($week==1)
return rs_week1;
else if ($week==2)
return rs_week2;
}

Does this sounds like a better/easier solution? Actually, now that I think about it this definitely seems like the way to go.

How would you write this function in asp? It's probably extremely easy..I'm just so used to php I forgot ;)

thanks for the help!!!



 
Thanks anyways for the help...I solved my problem. In case anyone else happens to run into a similar issue I'll write a quick overview of what I did.

*****pseudocode*****
function get_rs(current_week)
{
rs_anyweek=query with current_week
Set get_rs = rs_anyweek
}

while(rs_week)
{
current_week=rs_week->get(week)

Set rs_anyweek = get_rs(current_week)
}

So it actually saved me quite a bit of code..instead of 16 queries I just have one query inside of a function and pass the parameter for week into that function.

Thanks for the help!
 
Glad you found something that works. Sorry I didn't have a chance to get back to you earlier.

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top