我有一个带有简单select语句的存储过程,其中我返回json:
SELECT A, B, C
FROM 123
FOR JSON AUTO
这很好用。但是,如果我调用存储过程,结果的名称是:JSON_F52E2B61-18A1-11d1-B105-00805F49916B
如何指定返回值的名称?
谢谢!
答案 0 :(得分:1)
您可以将其作为子查询调用,并将其命名为:
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
返回:
MyJson
[{"a":123,"b":"do re mi","c":"fa so la"}]