The multi-part identifier "dbo.Staff.Firm" could not be bound. with a UNION

  • 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 ......

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • 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.

  • DOH! It figures. It was a long day. I was thinking I was likely not looking at it right.:pinch:

  • And of course that fixed everything. :blush:

  • 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