January 11, 2010 at 3:42 pm
You need to use the alias name that you've given dbo.Staff in the UNIONed queries. You've aliased all but the first query as Staff_3, Staff_2, etc. You're SELECT should read
SELECT alias.Firm,
......
FROM ......
January 11, 2010 at 4:07 pm
UNION
SELECT
dbo.Staff.Firm, --dbo.Staff is aliased Staff_3, this should be Staff_3.Firm
Person_3.FullName AS Name, CAST('NONE' AS varchar(5)) AS Department, Address_2.City, Address_2.StateCode AS State,
Company_3.Name AS Company
FROM dbo.Staff AS Staff_3 INNER JOIN
dbo.Person AS Person_3 ON Staff_3.PersonID = Person_3.PersonID INNER JOIN
dbo.StaffAddress AS StaffAddress_4 ON Staff_3.StaffID = StaffAddress_4.StaffID INNER JOIN
dbo.Address AS Address_2 ON StaffAddress_4.AddressID = Address_2.AddressID INNER JOIN
dbo.Company AS Company_3 ON Person_3.CompanyID = Company_3.CompanyID
WHERE (Staff_3.DepartmentID IS NULL)
UNION
See my comment above. Similar changes should be made in the other unioned queries where you have aliased dbo.Staff.
January 12, 2010 at 7:00 am
DOH! It figures. It was a long day. I was thinking I was likely not looking at it right.:pinch:
January 12, 2010 at 7:02 am
And of course that fixed everything. :blush:
January 12, 2010 at 8:09 am
Looks like a trees and forest issue. Glad to be able to help.
Viewing 5 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply