The following code runs and behaves as expected. However, as the image shows, SSMS is complaining that the columns from the GEN_NEW
sub-select are invalid. (Actual error popping up next to the mouse is "Invalid column name".)
Am I doing something wrong? How can I convince the SSMS parser that those columns really are valid? It's annoying to have SSMS barking when the code actually works.
MERGE
INTO
General.Associate GA
USING
(
SELECT
GEN_ID
,GEN_JSON
FROM
OPENJSON( @jsonResult, '$.entities' )
WITH (
GEN_ID UNIQUEIDENTIFIER '$.id'
,GEN_JSON NVARCHAR(MAX) '$' AS JSON
)
) GEN_NEW
ON GA.GEN_ID = GEN_NEW.GEN_ID
WHEN MATCHED
AND GA.GEN_JSON <> GEN_NEW.GEN_JSON
THEN UPDATE
SET
GA.GEN_JSON = GEN_NEW.GEN_JSON
WHEN NOT MATCHED BY TARGET
THEN INSERT (GEN_JSON)
VALUES (GEN_NEW.GEN_JSON)
;
Here's a snapshot of SSMS's complaints:
SSMS Version: 19.0.2 SQL Server Version: 15.0.2101.7
Edit: This is not an intellisense issue as Peter B suggested. The columns in question are part of the sub-query, not something outside the query.