Solved

The correlation name 'ej' is specified multiple times in a FROM clause

Posted on 2008-10-09
2
1,567 Views
Last Modified: 2010-05-18
Im trying to do this but keep getting the error shown in the title

Not sure what im missing
select DISTINCT
e.EmployeeID,
es.EmployeeStatus AS Status,
e.EmployeeDescNoID AS Emp_Name,
e.WindowsUserName AS LoginID,
e.DisplayEmployeeID AS UserID,
e.ExtNoUD AS Extension,
e.FFWMobileUD AS FFWMobile,
e.WorkEmail AS Email,
-- profitcentre
-- department
e.EliteNoUD AS SectionNumber,
e.SecretaryNameUD AS Secretary,
e.LocationUD AS Location,
ej.PostID AS Position
 
FROM [Cascade].dbo.Employee e
 
JOIN [Cascade].dbo.EmployeeJobs ej
  ON e.EmployeeID = ej.EmployeeID
 
JOIN [Cascade].dbo.Employee_Status es
  ON e.EmployeeID = es.EmployeeID
 
LEFT OUTER JOIN (select t1.JobTitle, t1.EmployeeID
                   from [Cascade].dbo.EmployeeJobs t1 
                   join (select employeeId, min(Sequence) as sequence 
                           from [Cascade].dbo.EmployeeJobs 
                          group by employeeID
                        ) t2
                     on t1.employeeid = t2.employeeID 
                    and t1.Sequence  = t2.Sequence
                 ) ej
  ON e.EmployeeID = ej.EmployeeID
 
WHERE es.EmployeeStatus = 'Current'

Open in new window

0
Comment
Question by:mooriginal
2 Comments
 
LVL 39

Accepted Solution

by:
appari earned 500 total points
ID: 22679394
you are using same alias name ej in two places,
change one of them to a different name like ej1

select DISTINCT
e.EmployeeID,
es.EmployeeStatus AS Status,
e.EmployeeDescNoID AS Emp_Name,
e.WindowsUserName AS LoginID,
e.DisplayEmployeeID AS UserID,
e.ExtNoUD AS Extension,
e.FFWMobileUD AS FFWMobile,
e.WorkEmail AS Email,
-- profitcentre
-- department
e.EliteNoUD AS SectionNumber,
e.SecretaryNameUD AS Secretary,
e.LocationUD AS Location,
ej.PostID AS Position
 
FROM [Cascade].dbo.Employee e
 
JOIN [Cascade].dbo.EmployeeJobs ej
  ON e.EmployeeID = ej.EmployeeID
 
JOIN [Cascade].dbo.Employee_Status es
  ON e.EmployeeID = es.EmployeeID
 
LEFT OUTER JOIN (select t1.JobTitle, t1.EmployeeID
                   from [Cascade].dbo.EmployeeJobs t1 
                   join (select employeeId, min(Sequence) as sequence 
                           from [Cascade].dbo.EmployeeJobs 
                          group by employeeID
                        ) t2
                     on t1.employeeid = t2.employeeID 
                    and t1.Sequence  = t2.Sequence
                 ) ej1
  ON e.EmployeeID = ej1.EmployeeID
 
WHERE es.EmployeeStatus = 'Current'

Open in new window

0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 22679503
appari: is correct
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

816 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

10 Experts available now in Live!

Get 1:1 Help Now