如果我想将JSON字符串作为变量传递,并在SQL Server中使用FOR JSON PATH
将其嵌入到另一个JSON对象中,我该怎么做呢?
缩略示例:
DECLARE @empInfo nvarchar(max), @msg nvarchar(max)
SET @empInfo = (SELECT '00500' as 'Company', '10000' as 'Employee' FOR JSON PATH, WITHOUT_ARRAY_WRAPPER)
SET @msg = (
SELECT
@empInfo as 'EmployeeInformation',
'other data' as 'Other Data'
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
)
SELECT @msg
在这种情况下,@msg的格式会很差.EmployeeInformation should not用引号括起来,字符被转义.
{"EmployeeInformation":"{\"Company\":\"00500\",\"Employee\":\"10000\"}","Other Data":"other data"}