Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old August 1st, 2004, 08:21 AM
Flona_25 Flona_25 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 8 Flona_25 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Please Help...Urgent!

How can I write a Select Statement from two tables that are related?

for example that i want to select the department name from a dept table
for a speacial User..where the user is in a table users and has a foriegn key which is the dept no.

i want to display the departmnet name in a text box..lets say txtdept

Thanx in advance for you help.

Reply With Quote
  #2  
Old August 1st, 2004, 10:12 PM
shinu shinu is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 27 shinu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 5 m 40 sec
Reputation Power: 0
try this

try this:
assume that table dept has deptcode and description as fields and
table user has deptcode and name.

the user name is stored in the string variable called usename.

and the querry is,

"select b.description from user a, dept b where a.name = '" & username & "' and b.deptcode = a.deptcode"

create a recordset using this querry and use the value of that recordset as the text property of the textbox, say, txtdept.text = recordset.fields(0).

does it work ?

shinu.

Reply With Quote
  #3  
Old August 10th, 2004, 12:42 PM
Mythomep Mythomep is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Zaandam, The Netherlands
Posts: 70 Mythomep User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 37 sec
Reputation Power: 4
Send a message via MSN to Mythomep
Hi,

If you have two tables and have a foreign key in one, then you can use the INNER JOIN statement in your SQL. The solution that shinu gave is an embeded inner join. They used to make those in the early days. Anyway:

Code:
 SELECT User.description, Departments.name
 FROM User INNER JOIN Departments ON User.Department_ID = Departments.Department_ID
 WHERE User.name = 'Username'
 


This is the same as Shinu, but more efficient on the database. Since the join statement has a much better hashing technique, where the join in the where statements results in a table scan.

If you have any questions, feel free to ask them.

Grtz.©

M.

P.s. It is not my intention to step on toes, don't regard this message as being so.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Please Help...Urgent!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway