Solved

SyBase SQL Syntax

Posted on 2013-10-25
4
662 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Read about why it is more lucrative for an IT company to participate in government projects.
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…

830 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