1
votes

I was exploring new Transact SQL JSON capabilities by running various example snippets in my regular SQL Server 2014 Management Studio against clean install of SQL Server 2016 Express. I've started to understand how it works, but suddenly got bitten by

Must declare the scalar variable

For example, this loading snippet worked before:

SELECT @json = BulkColumn
FROM OPENROWSET (BULK 'C:\JSON\Books\book.json', SINGLE_CLOB) as j

but now it spews:

Msg 137, Level 15, State 1, Line 1
Must declare the scalar variable "@json".

There are much more snippets from MSDN which either ceased to work or don't work when pasted to query window.

Why this happened? Did I break something? Is it related to older Management Studio and newer database engine?

1
I"m not familiar with that snippet or JSON data types, but that is a totally expected error message for that code. That code would never have worked in the past without that error message. The missing code at the start is something like DECLARE @json VARCHAR(4000)Nick.McDermaid

1 Answers

1
votes

You need to Declare variables,those may be just examples to show how it works..

Declare @json nvarchar(max)
SELECT @json = BulkColumn
 FROM OPENROWSET (BULK 'C:\JSON\Books\book.json', SINGLE_CLOB) as j