Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
428 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Some other pages relevant to these blogs include:
You can also book hourly online consultancy for your time zone with one of our 7 expert trainers!
|
Using JSON in SQL Server, including the new SQL 2025 functions Part seven of an eight-part series of blogs |
|---|
|
SQL Server 2025 introduces a new JSON data type and some new JSON functions - we thought we'd use this as an excuse to create this masterclass on working with JSON in SQL Server
|
This is a natural extension of everything that this blog has talked about so far. The fantastic thing about the way that SQL Server deals with JSON is that it doesn't differentiate in queries between whether data comes in table or JSON format, so you can join the two types of data together. Like this, in fact:
-- create a variable to hold the JSON text
DECLARE @json_text NVARCHAR(MAX)
-- set this variable to be the contents of the films table
SELECT @json_text = f.BulkColumn
FROM OPENROWSET(
BULK 'C:\wiseowl\films.json',
SINGLE_CLOB
) as f;
-- create a CTE to hold the list of films from the JSON file
WITH json_films AS (
SELECT
-- get the title and director from the JSON
f.Title,
f.Director
FROM
-- shred the "results" part of the JSON into rows
OPENJSON(@json_text, '$.results')
WITH(
Title nvarchar(200) '$.title',
Director nvarchar(200) '$.director'
) AS f
)
SELECT
-- get the title and director from the JSON
f.Title,
f.Director,
-- show fields from the Wise Owl movies
-- database table of films
sql_films.OscarWins AS Oscars,
sql_films.RunTimeMinutes as FilmLength,
sql_films.RunTimeMinutes
FROM
-- some of the films in the movies database have extra info
--(eg Star Wars: 'Episode VI - Return of the Jedi')
json_films as f
LEFT JOIN Film as sql_films ON
LOWER(sql_films.Title) LIKE '%' || LOWER(f.Title) || '%'
Here's what this gives for the Wise Owl movies database:

The left columns come from the JSON file, the right from a linked SQL Server table.
So you no longer have to process your JSON and SQL Server data separately - you can join them together and work with them in one place!
Some other pages relevant to these blogs include:
You can also book hourly online consultancy for your time zone with one of our 7 expert trainers!
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2025. All Rights Reserved.