Select Top (1000000) tblAssets.AssetID,
tblAssets.AssetName,
tblAssets.Domain,
tblAssets.IPAddress,
tblAssets.Firstseen,
tblAssets.Lastseen,
tblAssets.Lasttried,
tsysOS.Image As icon
From tblAssets
Inner Join tblRegistry As tblRegistrya On tblAssets.AssetID =
tblRegistrya.AssetID And tblRegistrya.Valuename = 'TSAppCompat'
Left Outer Join tsysOS On tsysOS.OScode = tblAssets.OScode
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Where tblRegistrya.Value = '1' And tblAssetCustom.State = 1
Order By tblAssets.AssetName,
tblAssets.Domain