简体   繁体   中英

OpenJson in SQL server 2017 : The multi-part identifier could not be bound

In the [DB_DW].[dbo].DIM_DW_MEETINGS I have a Json Column called Individuals :

[  
   {  
      "Activity_id":1787040082,
      "IndividualID":52528443
   },
   {  
      "Activity_id":1787040082,
      "IndividualID":99312125
   }
]

I now want to execute this query in sql :

SELECT DISTINCT
    *
FROM [DB_DW].dbo.DIM_DW_FACT_ACTIVITIES Fact
INNER JOIN [DB_DW].[dbo].DIM_DW_MEETINGS dimMeetings
    ON Fact.Activity_TECH_KEY = dimMeetings.MEETING_TECH_KEY
LEFT JOIN (SELECT
        *
    FROM OPENJSON(
    (dimMeetings.Individuals)
    ) WITH (
    IndividualID INT '$.IndividualID',
    Activity_id INT '$.Activity_id'
    )) query
    ON query.Activity_id = dimMeetings.Meeting_ID

but I always have this error :

The multi-part identifier "dimMeetings.Individuals" could not be bound.

Use outer apply to the OPENJSON function

    SELECT DISTINCT
    *
    FROM DIM_DW_FACT_ACTIVITIES Fact
    INNER JOIN DIM_DW_MEETINGS dimMeetings
    ON Fact.Activity_TECH_KEY = dimMeetings.MEETING_TECH_KEY
    OUTER APPLY OPENJSON(
    (dimMeetings.Individuals)
            ) WITH (
    IndividualID INT '$.IndividualID',
    Activity_id INT '$.Activity_id'
    ) query

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM