Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



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

Posts: 14
Trades: 0
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
 
 
Register now for full access!
Old 11-20-2006, 07:22 PM Re: Assigning variables from 2 different Tables.
ExpressoDan's Avatar
Ultra Talker

Posts: 317
Name: This Space for Rent
Location: Georgia
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE

"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, 10:10 AM Re: Assigning variables from 2 different Tables.
Novice Talker

Posts: 14
Trades: 0
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 12:21 PM.. Reason: typos
ucmeicu is offline
Reply With Quote
View Public Profile
 
Old 11-21-2006, 12:16 PM Re: Assigning variables from 2 different Tables.
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 11-21-2006, 03:21 PM Re: Assigning variables from 2 different Tables.
Novice Talker

Posts: 14
Trades: 0
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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.15514 seconds with 12 queries