I need help to load data from JSON to a table but have them ordered/sorted and insert to table?
DECLARE @IN_DATESJSON NVARCHAR(MAX) = N'[{"CreatedDate":"2018-10-10T09:07:29Z"},{"CreatedDate":"2018-10-09T09:07:29Z"},{"CreatedDate":"2018-10-08T07:07:08Z"}]';
DECLARE @V_CALLSTBL AS TABLE (CreatedDate DATETIME);
IF (ISJSON(@IN_DATESJSON) = 1)
BEGIN
INSERT INTO @V_CALLSTBL
SELECT *
FROM OPENJSON (@IN_DATESJSON)
WITH (CreatedDate DATETIME2)
-- ORDER BY CreatedDate ASC -- THIS DOESN'T WORK*
END
SELECT * FROM @V_CALLSTBL;
CreatedDate
-----------------------
2018-10-10 09:07:29.000
2018-10-09 09:07:29.000
2018-10-08 07:07:08.000