Solved

SQL Statment

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

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…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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