Reply
Assigning variables from 2 different Tables.
Old 11-20-2006, 02:53 PM Assigning variables from 2 different Tables.
Novice Talker

Posts: 14
Hey Folks,
I'm working on a project that is calling for data from a couple of different tables in a database to be displayed on the same page. The problem is that in both of the tables, the data rows are labelled the same. What I'm thinking I need to do is assign a variable to each data row in each table, but I am having issues doing this.

For a quick example. Lets say I have a database 'blah' and in that database I have a table named: tbl1, and another table named tbl2. In each of these tables I have a row named 'id'.

I want to be able to show the data from the 'id' row from both tbl1 and tbl2.

How can I create a variable for the id in tbl1 and the id in tbl2?

Do I do it in the sql command?
Or something Else?

I tried to be as clear as I could.
Let me know if you need more details,
Thanks,
Alex
ucmeicu is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 11-20-2006, 06:22 PM Re: Assigning variables from 2 different Tables.
ExpressoDan's Avatar
Ultra Talker

Posts: 317
Name: This Space for Rent
Location: Georgia
Use "AS" in your sql statement where you basically rename the column name each time the sql script runs. It doesn't change the name in the table, it only changes for the script you are running.
Example:
SELECT id AS TBL_ONE_ID, OTHER_COLUMN, ANOTHER_COLUMN
FROM tbl1
__________________
Daniel
"I think therefore I am, I think." <!-- George Carlin
ExpressoDan is offline
Reply With Quote
View Public Profile Visit ExpressoDan's homepage!
 
Old 11-21-2006, 09:10 AM Re: Assigning variables from 2 different Tables.
Novice Talker

Posts: 14
If I do that, is it okay to run 2 sql querys on the same page? I've not done that before.
What I have done so far is:
"SELECT annuityID, insComp, annName, intRate AS reg_annuityID, reg_insComp, reg_annName, reg_intRate FROM tbl_bestpick"

it errors out. obviously I'm not doing this right.
Even if I do get that to work what do I do for the other table? Just put another Select statement in?

Last edited by ucmeicu : 11-21-2006 at 11:21 AM. Reason: typos
ucmeicu is offline
Reply With Quote
View Public Profile
 
Old 11-21-2006, 11:16 AM Re: Assigning variables from 2 different Tables.
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,945
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Your error is that you're misnaming intRate.

It should be (your other table).intRate as annuityID2 (or something else different).

Also, you CAN run two SQL queries on the same page. You just need to dump your results to arrays and work with them from there.

http://www.asp101.com/samples/db_getrows.asp

There's a good sample to get you started.
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 11-21-2006, 02:21 PM Re: Assigning variables from 2 different Tables.
Novice Talker

Posts: 14
Thanks guys!
That worked great!
ucmeicu is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Assigning variables from 2 different Tables.
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14081 seconds with 13 queries