Skip to main content
format code
Source Link
ypercubeᵀᴹ
  • 98.7k
  • 13
  • 215
  • 305

use json_query,

SELECT @@SERVERNAME AS [Servername], json_query(( SELECT [Name], [Recovery_Model_Desc]
FROM sys.databases WHERE name in ('master', 'model', 'msdb') FOR JSON PATH, WITHOUT_ARRAY_WRAPPER ) ) AS d FOR JSON PATH, ROOT('ServerInformation')

SELECT @@SERVERNAME AS [Servername],
json_query(( SELECT [Name], [Recovery_Model_Desc]  
    FROM sys.databases
    WHERE name in ('master', 'model', 'msdb')
    FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
    ) ) AS d
FOR JSON PATH, ROOT('ServerInformation')

use json_query,

SELECT @@SERVERNAME AS [Servername], json_query(( SELECT [Name], [Recovery_Model_Desc]
FROM sys.databases WHERE name in ('master', 'model', 'msdb') FOR JSON PATH, WITHOUT_ARRAY_WRAPPER ) ) AS d FOR JSON PATH, ROOT('ServerInformation')

use json_query,

SELECT @@SERVERNAME AS [Servername],
json_query(( SELECT [Name], [Recovery_Model_Desc]  
    FROM sys.databases
    WHERE name in ('master', 'model', 'msdb')
    FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
    ) ) AS d
FOR JSON PATH, ROOT('ServerInformation')
Source Link

use json_query,

SELECT @@SERVERNAME AS [Servername], json_query(( SELECT [Name], [Recovery_Model_Desc]
FROM sys.databases WHERE name in ('master', 'model', 'msdb') FOR JSON PATH, WITHOUT_ARRAY_WRAPPER ) ) AS d FOR JSON PATH, ROOT('ServerInformation')