create table #SVer(ID int,  Name  sysname, Internal_Value int, Value nvarchar(512))	insert #SVer exec master.dbo.xp_msver
declare @SmoRoot nvarchar(512)
exec master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\Setup', N'SQLPath', @SmoRoot OUTPUT

--insert into InstanceList
SELECT 
serverproperty(N'ComputerNamePhysicalNetBIOS') AS [Host_name],
serverproperty(N'ServerName') as [ServerName],
serverproperty(N'InstanceName') as [InstanceName],
GETDATE() as date_invent,
(select Value from #SVer where Name = N'ProductName') AS [Product],
SERVERPROPERTY(N'ProductVersion') AS [VersionString],
(select Value from #SVer where Name = N'Language') AS [Language],
(select Value from #SVer where Name = N'Platform') AS [Platform],
CAST(SERVERPROPERTY(N'Edition') AS sysname) AS [Edition],
(select Internal_Value from #SVer where Name = N'ProcessorCount') AS [Processors],
(select Value from #SVer where Name = N'WindowsVersion') AS [OSVersion],
(select Internal_Value from #SVer where Name = N'PhysicalMemory') AS [PhysicalMemory],
cast(SERVERPROPERTY('IsClustered') AS varchar) AS [IsClustered],
@SmoRoot AS [RootDirectory],
convert(sysname, serverproperty(N'collation')) AS [Collation]

drop table #SVer

SELECT
serverproperty(N'ComputerNamePhysicalNetBIOS') AS [Host_name],
GETDATE() as date_invent,
dtb.name AS [Database_Name],

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_int],
convert(sysname,DatabasePropertyEx(dtb.name,'Status')) as Database_status,
create_date,
dtb.compatibility_level AS [Database_CompatibilityLevel],
convert(sysname,DatabasePropertyEx(dtb.name,'Recovery')) AS [RecoveryModel],
convert(sysname,DatabasePropertyEx(dtb.name,'UserAccess')) AS [UserAccess],
convert(sysname,DatabasePropertyEx(dtb.name,'Updateability')) AS [ReadOnly]
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','IBM') then 1 else dtb.is_distributor end AS bit)=0 and CAST(isnull(dtb.source_database_id, 0) AS bit)=0)
ORDER BY
[Database_Name] ASC

            


			
			
