the query below throws the error mentioned in the title :
SELECT
Set_To_Value_ID,
CASE
WHEN Set_To_Variable_ID IS NOT NULL THEN Set_To_Variable_ID
WHEN Changed_In_SP IS NOT NULL THEN Changed_In_SP
WHEN Comment_Input IS NOT NULL THEN ( Select Comment FROM Process_Instance WHERE Process_Instance_ID = @Process_Instance_ID )
END AS Manual_Value
FROM Variables
WHERE Some_Irrelevant_Value = @Some_Irrelevant_Value
I know the error comes from the Comment_Input case because that's the value that should be returned from there.