How can we help you today? How can we help you today?

Why does my table Alias get removed when using OpenJSON?

As I've been learning how to shred Json objects in SQL, I'm finding some strange behavior with SQL Prompt. 

I have Json  with nested objects, that I shred like this: 
DECLARE @... NVARCHAR(MAX) = N'
[
   {
      "ProductID":594,
      "ProductName":"Sample",
      "OrgID":5876,
      "Numerics":{
         "Q1":"5",
         "Q2":"8",
         "Q3":"9",
         "Q4":"9",
         "Q5":"8"        
      }
   }
]'

SELECT oj.ProductID
     , oj.ProductName
     , oj.OrgID
     , p.[Key] AS Question
     , p.Value AS Answer
FROM
    OPENJSON(@Json)
    WITH ( ProductID INT
         , ProductName NVARCHAR(50)
         , OrgID INT
         , Numerics NVARCHAR(MAX) AS JSON ) AS oj
CROSS APPLY OPENJSON(oj.Numerics) AS p

If I format my code using Ctrl K+Y, the alias for "oj" drops in my CROSS APPLY.  This is particularly problematic when I have several nested objects that I CROSS APPLY in the same query and all aliases drop after formatting. 

Do you have any suggestions on how I can keep the table Alias alive in my following Joins?
John Harding
0

Comments

2 comments

  • Russell D
    This is a known issue we're looking into. I'll let you know when I have more information.
    Russell D
    0
  • Russell D
    We're still looking into this particular issue, apologies.
    Russell D
    0

Add comment

Please sign in to leave a comment.