Solved

SQL Statment

Posted on 2011-02-24
5
425 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

860 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