Relevance for SQL version

(name of it & " | Version: " & (if exists value “PatchLevel” of key “Setup” of key ((it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server” of native registry) then (value “PatchLevel” of key “Setup” of key ((it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server” of native registry) as string) else “Unknown”) & " | DataPath: " & (if exists value “SQLDataRoot” of key ((it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server” of native registry) then (value “SQLDataRoot” of key ((it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server” of native registry) as string) else “Not Found”)) of keys whose (exists value of it AND exists folder ((value “SQLDataRoot” of key ((it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server” of native registry) as string) & “\MSSQL\Data”) whose (exists files whose (name of it ends with “.mdf” OR name of it ends with “.ldf”) of it)) of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL”

unique value
unique values of (value “DisplayName” of it as string & " | " & (value “DisplayVersion” of it as string)) of keys whose (exists value “DisplayName” of it AND (value “DisplayName” of it as string as lowercase contains “sql server”)) of keys “Uninstall” of (keys “HKLM\Software\Microsoft\Windows\CurrentVersion” of (x64 registries;x32 registries))

(if exists key “HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL” of registry then
concatenation "; " of (names of keys of keys “HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL” of registry)
else “No SQL Server Instance”)

& " | "

(if exists key ("HKLM\SOFTWARE\Microsoft\Microsoft SQL Server" & (item 0 of substrings separated by “;” of it) & “\MSSQLServer\CurrentVersion”) of registry then
value “CurrentVersion” of key ("HKLM\SOFTWARE\Microsoft\Microsoft SQL Server" & (item 0 of substrings separated by “;” of it) & “\MSSQLServer\CurrentVersion”) of registry as string
else “No Version Info”)

Comparing Patch Value with Display version and then print value of Display version and display name

unique values of (value “DisplayName” of it as string & " | " & value “DisplayVersion” of it as string) of keys whose (exists value “DisplayVersion” of it AND exists value “DisplayName” of it AND exists key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server” of native registry AND (value “DisplayVersion” of it as string = (values “PatchLevel” of keys “Setup” of keys of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server” of native registry as string))) of keys “Uninstall” of keys “HKLM\Software\Microsoft\Windows\CurrentVersion” of (x64 registries;x32 registries)

(unique values of (value “DisplayName” of it as string & " | " & value “DisplayVersion” of it as string)) of keys whose (exists value “DisplayName” of it AND exists value “DisplayVersion” of it AND (value “DisplayName” of it as lowercase contains “sql”) AND (value “DisplayVersion” of it as string) is contained by (set of (it as string) of values “PatchLevel” of keys “Setup” of keys of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server” of native registry)) of keys “Uninstall” of keys “HKLM\Software\Microsoft\Windows\CurrentVersion” of (x64 registries; x32 registries)