Solved

SQL Statment

Posted on 2011-02-24
5
422 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
  • 2
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Sharath earned 200 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 300 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 300 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now