Q:

nested CASE not working

The below SQL query lets me find the Office 365 update channel.  But it does not handle the case when the Registry table has no entry for a computer. 
I have tried many different nested CASES, all fail badly.  I'm just a novice SQL guy.   Can someone point in the correct direction please? 
good but does not handle if tblRegistry is missing. 
SELECT
tblAssets. AssetName,
CASE 
    WHEN tblRegistry. Value = 'http://officecdn.microsoft.com/pr/492350f6-3a01-4f97-b9c0-c7c6ddf67d60' THEN 'Monthly' 
    WHEN tblRegistry. Value = 'http://officecdn.microsoft.com/pr/7ffbc6bf-bc32-4f92-8982-f9dd17fd3114' THEN 'Semi-Annual' 
    WHEN tblRegistry. Value = 'http://officecdn.microsoft.com/pr/64256afe-f5d9-4f86-8936-8840a6a4f5be' THEN 'Monthly Targeted' 
    WHEN tblRegistry. Value = 'http://officecdn.microsoft.com/pr/b8f9b850-328d-4355-9145-c59439a0c4cf' THEN 'Semi-Annual Targeted'
    ELSE 'Bad-Registry'+'_'+tblRegistry. Value END AS o365channel
FROM tblAssets
INNER JOIN tblRegistry ON tblRegistry. AssetID = tblAssets. AssetID
WHERE (tblRegistry. Regkey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\Configuration') AND (tblRegistry. Valuename = 'UpdateChannel')

really bad
SELECT
tblAssets. AssetName,
CASE WHEN tblAssets. AssetName in 
    (
    select tblAssets. AssetName
    FROM tblAssets
    INNER JOIN tblRegistry ON tblRegistry. AssetID = tblAssets. AssetID
    WHERE (tblRegistry. Regkey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\Configuration') AND (tblRegistry. Valuename = 'UpdateChannel')
    )
    select tblAssets. AssetName,
    CASE
        WHEN tblRegistry. Value = 'http://officecdn.microsoft.com/pr/492350f6-3a01-4f97-b9c0-c7c6ddf67d60' THEN 'Monthly' 
        WHEN tblRegistry. Value = 'http://officecdn.microsoft.com/pr/7ffbc6bf-bc32-4f92-8982-f9dd17fd3114' THEN 'Semi-Annual' 
        WHEN tblRegistry. Value = 'http://officecdn.microsoft.com/pr/64256afe-f5d9-4f86-8936-8840a6a4f5be' THEN 'Monthly Targeted' 
        WHEN tblRegistry. Value = 'http://officecdn.microsoft.com/pr/b8f9b850-328d-4355-9145-c59439a0c4cf' THEN 'Semi-Annual Targeted'
        ELSE 'Bad-RegKey'+'_'+tblRegistry. Value
    END
ELSE 'Bad-RegMissing'
END AS o365channel
FROM tblAssets

Thanks in advance,
ccutler

A:

Try this:
SELECT tblAssets. AssetName,
       CASE 
            WHEN tblRegistry. Value = 'http://officecdn.microsoft.com/pr/492350f6-3a01-4f97-b9c0-c7c6ddf67d60' THEN 'Monthly' 
            WHEN tblRegistry. Value = 'http://officecdn.microsoft.com/pr/7ffbc6bf-bc32-4f92-8982-f9dd17fd3114' THEN 'Semi-Annual' 
            WHEN tblRegistry. Value = 'http://officecdn.microsoft.com/pr/64256afe-f5d9-4f86-8936-8840a6a4f5be' THEN 'Monthly Targeted' 
            WHEN tblRegistry. Value = 'http://officecdn.microsoft.com/pr/b8f9b850-328d-4355-9145-c59439a0c4cf' THEN 'Semi-Annual Targeted'
            ELSE 'Bad-Registry'+'_'+tblRegistry. Value
       END AS o365channel
FROM tblAssets
LEFT JOIN tblRegistry
    ON tblRegistry. AssetID = tblAssets. AssetID
    AND (tblRegistry. Regkey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\Configuration')
    AND (tblRegistry. Valuename = 'UpdateChannel')

