I want to return JSON or a Table result set (normal) based on a parameter that I am passing to a SQL Server stored procedure.
我想基于我传递给SQL Server存储过程的参数返回JSON或表结果集(正常)。
SELECT
emp.Name,
emp.EmpID
FROM
Employee emp
ORDER BY
emp.Name
FOR JSON Path;
This will return one column with a string JSON result.
这将返回一个包含字符串JSON结果的列。
I want to make this optional based on a parameter. Basically I want to re-use the stored procedure for JSON as well as normal result.
我想根据参数使这个可选。基本上我想重用JSON的存储过程以及正常结果。
1 个解决方案
#1
0
Sql key words or objects name ie column name or table name can not be used directly as parameter,
Sql关键字或对象名称即列名或表名不能直接用作参数,
You have and alternate write dynamic SQL in side SP.
您在侧面SP中具有备用写入动态SQL。
Note: It will have performance hit as it is dynamic SQL.
注意:由于它是动态SQL,因此会受到性能影响。
suggestion: Write two sp .
建议:写两个sp。
#1
0
Sql key words or objects name ie column name or table name can not be used directly as parameter,
Sql关键字或对象名称即列名或表名不能直接用作参数,
You have and alternate write dynamic SQL in side SP.
您在侧面SP中具有备用写入动态SQL。
Note: It will have performance hit as it is dynamic SQL.
注意:由于它是动态SQL,因此会受到性能影响。
suggestion: Write two sp .
建议:写两个sp。