Skip to content

Instantly share code, notes, and snippets.

@bertwagner
Created February 19, 2017 14:29
Show Gist options
  • Save bertwagner/d10fcdb2c2e80506911f3469428726d3 to your computer and use it in GitHub Desktop.
Save bertwagner/d10fcdb2c2e80506911f3469428726d3 to your computer and use it in GitHub Desktop.
Parsing JSON in pre-2016 SQL Server
-- Let's compare how quick Phil Factor's JSON parsing function does against the new SQL 2016 functions
-- Phil's parseJSON function can be downloaded from https://www.simple-talk.com/sql/t-sql-programming/consuming-json-strings-in-sql-server/
SELECT years.StringValue AS Year, makes.StringValue AS Make, models.StringValue AS Model FROM dbo.parseJSON(@cars) models
INNER JOIN dbo.parseJSON(@cars) years ON models.parent_ID = years.parent_ID
INNER JOIN dbo.parseJSON(@cars) makes ON models.parent_ID = makes.parent_ID
WHERE models.NAME = 'model' AND models.StringValue = 'Golf' AND years.NAME = 'year' AND makes.NAME = 'make'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment