• You can't declare variables in a view, and of course views can't take parameters. You use variables in number of places:

    -- as a column and in CASE expressions in the SELECT clause;

    -- as parameters to functions called in the SELECT clause;

    -- in the join conditions of almost every joined table or view.

    What will you use for those values in a view?

    If you need an object that can be used in the FROM clause of a select statement and also accepts parameters that can be used in the query, you could turn this code into an inline table-valued function.

    As an aside, calling scalar functions in a SELECT clause can really hurt performance. You call the dbo.reportNotesExist function twice in your SELECT clause. That function will be called twice for every row that the query returns - if you get 1,000 rows, the function will have to run 2,000 times.

    Jason Wolfkill