1

I have a row:

id, shipping_data, line_data
0, '[{"name": "Greg", "Address": "test address"}]', '[{"products": "apple", "cost": "0.50"'}'

and I want to expand the row to display all data in one row.

I tried using multiple cross applies:

SELECT id, A.*, B.*
FROM table t
CROSS APPLY OPENJSON(t.[shipping_data]) 
    WITH (
          name nvarchar(max),
          Address nvarchar(max)
         ) A;
CROSS APPLY OPENJSON(t.[line_data])
    WITH (
          products nvarchar(max),
          cost nvarchar(max)
         ) B;
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
apolloSN
  • 67
  • 5
  • What is the issue ? Post the result what you are getting and Expected result – Roshan Nuvvula Jun 27 '22 at 02:54
  • 4
    Drop the `;` after your `A` alias ..... the `;` is a statement **terminator** and thus your statements ends there - the second `CROSS JOIN` is not part of your `SELECT` statement anymore.... – marc_s Jun 27 '22 at 03:55
  • Also the `line_data` isn't a valid JSON value. Perhaps that's a transcription error when posting the question? – AlwaysLearning Jun 27 '22 at 09:51
  • I also suggest you rethink those data types. For example `cost should be `decimal(9,2)` and the text columns should not be `max` – Charlieface Jun 27 '22 at 12:38

0 Answers0