exec sp_executesql N' DECLARE @is_policy_automation_enabled bit SET @is_policy_automation_enabled = (SELECT CONVERT(bit, current_value) FROM msdb.dbo.syspolicy_configuration WHERE name = ''Enabled'') SELECT ''Server[@Name='' + quotename(CAST( serverproperty(N''Servername'') AS sysname),'''''''') + '']'' + ''/Database[@Name='' + quotename(dtb.name,'''''''') + '']'' AS [Database_Urn], dtb.name AS [Database_Name], dtb.create_date AS [Database_CreateDate], suser_sname(dtb.owner_sid) AS [Database_Owner], case when 1=@is_policy_automation_enabled and exists (select * from msdb.dbo.syspolicy_system_health_state where target_query_expression_with_id like ''Server''+ ''/Database\[@ID='' + convert(nvarchar(20),dtb.database_id) + ''\]%'' ESCAPE ''\'') then 1 else 0 end AS [Database_PolicyHealthState], dtb.recovery_model AS [Database_RecoveryModel], dtb.compatibility_level AS [Database_CompatibilityLevel], dtb.collation_name AS [Database_Collation], case when DATABASEPROPERTY(dtb.name,''IsShutDown'') is null then 0x200 else 0 end | case when 1 = dtb.is_in_standby then 0x40 else 0 end | case when 1 = dtb.is_cleanly_shutdown then 0x80 else 0 end | case dtb.state when 1 then 0x2 when 2 then 0x8 when 3 then 0x4 when 4 then 0x10 when 5 then 0x100 when 6 then 0x20 else 1 end AS [Database_Status], ISNULL(dmi.mirroring_role,0) AS [Database_MirroringRole], ISNULL(dmi.mirroring_state + 1, 0) AS [Database_MirroringStatus], dtb.recovery_model AS [RecoveryModel], dtb.user_access AS [UserAccess], dtb.is_read_only AS [ReadOnly], dtb.name AS [Database_DatabaseName2] FROM master.sys.databases AS dtb LEFT OUTER JOIN sys.database_mirroring AS dmi ON dmi.database_id = dtb.database_id WHERE (CAST(case when dtb.name in (''master'',''model'',''msdb'',''tempdb'') then 1 else dtb.is_distributor end AS bit)=@_msparam_0 and CAST(isnull(dtb.source_database_id, 0) AS bit)=@_msparam_1 and ( case when DATABASEPROPERTY(dtb.name,''IsShutDown'') is null then 0x200 else 0 end | case when 1 = dtb.is_in_standby then 0x40 else 0 end | case when 1 = dtb.is_cleanly_shutdown then 0x80 else 0 end | case dtb.state when 1 then 0x2 when 2 then 0x8 when 3 then 0x4 when 4 then 0x10 when 5 then 0x100 when 6 then 0x20 else 1 end ) & (@_msparam_2)=0) ORDER BY [Database_Name] ASC',N'@_msparam_0 nvarchar(4000),@_msparam_1 nvarchar(4000),@_msparam_2 nvarchar(4000)',@_msparam_0=N'0',@_msparam_1=N'0',@_msparam_2=N'62'