Q:

Case statement causing error - No column name was specified for column 4 of 'a'

This query is designed so that each row will have a unique NAME value.
The query works fine except when I introduced the SELECT CASE statement to select ROLENAME. When this is added, I get the error 

No column name was specified for column 4 of 'a'.

How can this be resolved?
 SELECT *
 FROM 
     (SELECT 
          NAME, CREATE_DATE, OTHERNAME,
          CASE 
             WHEN ID = 'test' THEN ROLENAME
          END,
          STATUS,
          ROW_NUMBER() OVER(PARTITION BY NAME ORDER BY NAME DESC) AS RowNumber
      FROM   
          BUSRULES br1 
      INNER JOIN 
          BUSRULES br2 ON br1.ID_NUM = br2.ID_NUM 
      INNER JOIN 
          BUSRULES br3 ON br1.ID_NUM = br3.ID_NUM 
      INNER JOIN 
          dbo.MDI ON NAME = br3.VALUE_TXT 
      INNER JOIN 
          (PERSON
      LEFT JOIN 
          OP_TYPE ON OP_CASE.ID_NUM = OP_TYPE.ID_NUM) 
            ON OP_ID_NUM = OCO_OP_ID_NUM 
      WHERE  
          br1.KEY_TXT = 'EVENT' 
          AND br1.VALUE_TXT = 'YES' 
          AND br2.ABR_KEY_TXT = 'LIST' 
          AND br2.ABR_VALUE_TXT = 'test'
          AND br3.ABR_KEY_TXT = 'NAME') AS a
WHERE
    a.RowNumber = 1

A:

Try to modify :
CASE WHEN ID = 'test'
            THEN ROLENAME
        END

into :
CASE WHEN ID = 'test'
            THEN ROLENAME
        END AS ROLENAME

The reason is because when you use CASE clause, it will have no name, unless you define it

