This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Lax (default: function will return an error if invalid JSON path specified | |
SELECT JSON_VALUE('{ "Color" : "Red" }', '$.Shape') --lax is the default, so you don't need to be explicitly state it | |
-- Output: NULL | |
SELECT JSON_VALUE('{ "Color" : "Red" }', 'lax $.Shape') | |
-- Output: NULL | |
-- Strict: function will return an error if invalid JSON path specified | |
SELECT JSON_VALUE('{ "Color" : "Red" }', 'strict $.Shape') | |
-- Output: Property cannot be found on the specified JSON path. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @jsonData nvarchar(max) = N'{ "createDate" : "2017-03-28T12:45:00.000Z" }' | |
-- SQL's JSON_VALUE() will read in the JSON date time as a string | |
SELECT JSON_VALUE(@jsonData, '$.createDate') | |
-- Output: 2017-03-28T12:45:00Z | |
-- If we want to read it in as a SQL datetime2, we need to use a CONVERT() (or a CAST()) | |
SELECT CONVERT(datetime2, JSON_VALUE(@jsonData, '$.createDate')) | |
-- Output: 2017-03-28 12:45:00.0000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Drop and create our temporal and historical tables | |
IF OBJECT_ID('dbo.CarInventory', 'U') IS NOT NULL | |
BEGIN | |
-- When deleting a temporal table, we need to first turn versioning off | |
ALTER TABLE dbo.CarInventory SET ( SYSTEM_VERSIONING = OFF ) | |
DROP TABLE dbo.CarInventory | |
DROP TABLE dbo.CarInventoryHistory | |
END; | |
CREATE TABLE CarInventory | |
( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<opml version="1.0"> | |
<head> | |
<title>Bert's mostly SQL subscriptions in feedly Cloud</title> | |
</head> | |
<body> | |
<outline text="Marketing" title="Marketing"> | |
<outline type="rss" text="Signal v. Noise" title="Signal v. Noise" xmlUrl="https://signalvnoise.com/posts.rss" htmlUrl="https://m.signalvnoise.com"/> | |
<outline type="rss" text="Austin Kleon" title="Austin Kleon" xmlUrl="http://feeds2.feedburner.com/AustinKleon" htmlUrl="https://austinkleon.com"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @garage nvarchar(1000) = N'{ "Cars": [{ "Make": "Volkswagen", "Model": { "Base": "Golf", "Trim": "GLI" }, "Year": 2003, "SellDate" : "2017-02-17T00:00:00.000Z" }, { "Make": "Subaru", "Model": { "Base": "Impreza", "Trim": "Premium" }, "Year": 2016, "PurchaseDate": "2015-08-18T00:00:00.000Z" },{ "Make": "Volkswagen", "Model": { "Base": "Golf", "Trim": "GTI" }, "Year": 2017, "PurchaseDate": "2017-02-19T00:00:00.000Z" }] }' | |
-- I realize it's not worth keeping the original Volkswagen in my @garage data any longer, so let's completely remove it. | |
-- Note, if we use NULL as per the MSDN documentation, we don't actually remove the first car element of the array - it just gets replaced with NULL | |
-- This is problematic if we expect the indexes of our array to shift by -1. | |
SELECT JSON_MODIFY(@garage, '$.Cars[0]', NULL) | |
-- Output: { "Cars": [null, { "Make": "Subaru", "Model": { "Base": "Impreza", "Trim": "Premium" }, "Year": 2016, "PurchaseDate": "2015-08-18T00:00:00.000Z" },{ "Make": "Volkswagen", "Model": { "Ba |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Get a Quote", | |
"intents": [ | |
{ | |
"intent": "AutoInsurance", | |
"examples": [ | |
{ | |
"text": "auto" | |
}, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ | |
"Label": "2015", | |
"Value": "2015" | |
}, { | |
"Label": "2016", | |
"Value": "2016" | |
}, { | |
"Label": "2017", | |
"Value": "2017" | |
}] |
This file has been truncated, but you can view the full file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE Sandbox; | |
DROP TABLE IF EXISTS dbo.XmlVsJSON | |
CREATE TABLE dbo.XmlVsJson | |
( | |
Id INT IDENTITY PRIMARY KEY, | |
XmlData XML, | |
JsonData NVARCHAR(MAX) | |
) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder