Diomedes
Diomedes

Reputation: 658

SQL Server 2016 For JSON return name

I have a stored procedure with a simple select statement in which I return json:

SELECT A, B, C
FROM 123
FOR JSON AUTO

This works fine. However, the name of the result, if I call the stored procedure, is something like: JSON_F52E2B61-18A1-11d1-B105-00805F49916B

How can I specify the name of the return value?

Thanks!

Upvotes: 2

Views: 209

Answers (1)

SqlZim
SqlZim

Reputation: 38073

You could call is as a subquery and alias it like so:

create table t (a int, b varchar(32), c varchar(32));
insert into t values (123, 'do re mi','fa so la' );
select (select a, b, c from t for json auto) as MyJson;

dbfiddle.uk: http://dbfiddle.uk/?rdbms=sqlserver_2016&fiddle=2fc249147c9780fbd4d0ab307740b029

returns:

MyJson
[{"a":123,"b":"do re mi","c":"fa so la"}]

Upvotes: 2

Related Questions