• I don't think you can use the IF...ELSE construct in a view.

    You'll need a stored procedure for that.

    The error might have given this away:

    Msg 156, Level 15, State 1, Procedure Test, Line 3

    Incorrect syntax near the keyword 'IF'.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP