0

I need to get result of sql query in JSON format via MSSQL 2014. I have wrote this code:

SELECT bc.Id, bc.CityName, bc.ProvinceId FROM BusCity AS bc WHERE bc.Country=2 FOR JSON AUTO

But I am getting an error:

Incorrect syntax near 'JSON'.

Is this possible? How to do this?

1

1 Answer 1

1

You running 2016 or higher?

FOR JSON was introduced then.

Type

SELECT @@Version

To find out what version you're running.

https://learn.microsoft.com/en-us/sql/relational-databases/json/format-query-results-as-json-with-for-json-sql-server

Sign up to request clarification or add additional context in comments.

2 Comments

Microsoft SQL Server 2014 (SP2) (KB3171021) - 12.0.5000.0 (X64) Jun 17 2016 19:14:09 Copyright (c) Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)
Yup. It's not available on your version of SQL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.