?
Solved

SQL Statment

Posted on 2011-02-24
5
Medium Priority
?
430 Views
Last Modified: 2012-05-11
I would to grab data from 2 different tables with one sql statment , how can I do that .
one of my table has info about a job alog with a tech id and the other table has the name of this tech id , I would like to display the job info and also the full name of this tech id.
here are my main SQL statment:
strsql = " select STATIONID, STATUS, TECHID from SVC06103 where WORKORDNUM = '" & StrWORTVNum.Value & "'"

my other table SVC00100 has the "TECHID" , "NAME", and "OFFID" fields. I would like to pull the NAME and OFFID from this table
Can someone help me with the correct statment
Thanks
David
0
Comment
Question by:taverny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 41

Accepted Solution

by:
Sharath earned 800 total points
ID: 34976280
strsql = " select t1.STATIONID, t1.STATUS, t1.TECHID,t2.NAME,t2.OFFID from SVC06103  t1 JOIN SVC00100  t2 ON t1.TECHID = t2.TECHID where t1.WORKORDNUM = '" & StrWORTVNum.Value & "'"
0
 
LVL 17

Assisted Solution

by:dbaSQL
dbaSQL earned 1200 total points
ID: 34976300

select s.STATIONID, s.[STATUS], s.TECHID,ss.[name],ss.offid
from SVC06103 s JOIN SVC00100 ss
 on s.techid = ss.techid
where s.WORKORDNUM = the given value
0
 

Author Comment

by:taverny
ID: 34976512
Thanks the code works and you both got it right . I know it's not part of my question but if I wanted to join it whith a 3rd table on StationID , how would I do that on the same SQL.
If I understand how to use the join would it be something like that?:

strsql = " select t1.STATIONID, t1.[STATUS], t1.TECHID, t2.[NAME], t2.OFFID, t3.[Description] from SVC06103  t1 JOIN SVC00100  t2 ON t1.TECHID = t2.TECHID JOIN SVC0615 t3 ONt1.STATIONID = t3.STATIONID where t1.WORKORDNUM = '" & StrWORTVNum.Value & "'"

Thanks in advance
0
 
LVL 17

Assisted Solution

by:dbaSQL
dbaSQL earned 1200 total points
ID: 34976524
Yes, that is correct.  If stationID is the equal value in both tables, that is correct.
0
 

Author Comment

by:taverny
ID: 34976641
Thank you it works
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question