Solved

SyBase SQL Syntax

Posted on 2013-10-25
4
633 Views
Last Modified: 2013-10-25
Hey guys,
 
I have 2 tables using SyBase SQL Anywhere 10
Employee Table
EmpNum
Firstname
Lastname
 
Sales Table
Transact
WhoStart (EmpNum)
WhoClosed   (EmpNum)
 
I want to return the transaction number and the first name’s of the employee who started and closed the sale. Usually the person who starts and closes is the same, but sometimes it’s not.
 
Help?
0
Comment
Question by:triphen
  • 2
4 Comments
 
LVL 26

Assisted Solution

by:wilcoxon
wilcoxon earned 250 total points
ID: 39601768
This should do what you want...
select s.Transact, es.Firstname, ec.Firstname
from Sales s, Employee es, Employee ec
where s.WhoStart = es.EmpNum
and s.WhoClosed = ec.EmpNum

Open in new window

0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 250 total points
ID: 39601812
I'd prefer to see ANSI join syntax used, the following is the equivalent of the prior comment:
SELECT
        s.Transact
      , es.Firstname AS StartByName
      , ec.Firstname AS ClosedByName
FROM Sales s
INNER JOIN Employee AS es ON s.WhoStart = es.EmpNum
INNER JOIN Employee AS ec ON s.WhoClosed = ec.EmpNum /* but might need LEFT JOIN ?? */
;

Open in new window

whilst it may be unlikely, if there is any chance that a record in that Sales tables does not have a value for WhoClosed, then you would want to use a LEFT JOIN

(I do hope you would always have values in WhoStart, but if some are missing then it too might need a left join)
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 39601850
Tangent...  Personally I *HATE* the ANSI join syntax.  I find it much harder to read than the "old" join syntax.  For this query, it's not bad but, as it gets more complex, the less I like ANSI joins.
0
 

Author Closing Comment

by:triphen
ID: 39601907
Thanks guys! I ended up using the ANSI join syntax.

left outer join dba.employee as es
on es.empnum = header.whostart

left outer join dba.employee as ec
on ec.empnum = header.whoclose
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A safe way to clean winsxs folder from your windows server 2008 R2 editions
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

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

13 Experts available now in Live!

Get 1:1 Help Now