Error on Join w/ Multiple Tables: Syntax Problem?

  • Greetings!

    I am trying to pull in columns from multiple tables but am getting an error when I run the code:

    Msg 4104, Level 16, State 1, Line 1

    The multi-part identifier "a.BOC" could not be bound.

    I am guessing that my syntax is completely off. Anybody able to shine some light on what the issue is with my code? Thanks!

    SELECT

    b.[PBCat]

    ,c.[VISN] --- I am trying to pull in the Column [VISN] from the Table [DIMSTA]. Current Status: --Failure

    ,a.[Station]

    ,a.[Facility]

    ,a.[CC]

    ,a.[Office]

    ,a.[BOC]

    ,a.[BOCName]

    ,left(a.[Appro],4) as [Appro]

    ,a.[FY]

    ,a.[Obs]

    ,a.[FTE]

    ,a.[Month]

    FROM [BudgetFormulation].[dbo].[ObjectClass] a

    Left Join [BudgetFormulation].[dbo].[DIMObject] b

    Left Join [BudgetFormulation].[dbo].[DIMSTA] c -- I assumed that I would need to add another left ---join statement.

    -- This could be the issue?

    On a.[BOC]=b.[BOC4]

    On a.[Station]=c.[Station] -- These are the unique keys that link the two tables [DIMSTA] & ---[ObjectClass]

    Order by BOC

  • You're missing the ON clauses.

    FROM [BudgetFormulation].[dbo].[ObjectClass] obj

    Left Join [BudgetFormulation].[dbo].[DIMObject] dobj ON <join condition>

    Left Join [BudgetFormulation].[dbo].[DIMSTA] dsta ON <join condition>

    And please, if you're going to alias the tables, use sensible aliases, not meaningless leters

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • That did the trick, I knew it would be something really obvious too. Thanks!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply