Is it Possible to use '' if 0'' and '' Set '' in a view

  • Hi

    Is it possible to use set or if keywords in a view

    Thanks

     

  • Hi,

    no, it is not possible.  You can only include a select statement in a view.

    If you're looking to use the SET statement then you want to perform an update so you should consider using a procedure instead.  You can however update the view under certain conditions - check BOL for specific conditions under which a view can be updated.

    Likewise, you cannot use IF in a view.  Again, consider using a stored procedure - or possibly a function.

    Hope that helps,

  • Vandy,

    As Carl pointed out, you cannot use SET or IF.  A view must consist of only 1 SELECT statement or the UNION of several SELECTs (don't believe that will be updateable).

    Instead of using IF, you can use CASE.  CASE may be used in the SELECT list and in the WHERE clause (with some caution).

    Once you have the view returning everything you want, you can use additional criteria in the WHERE clause of a SELECT that uses the view in the FROM clause.

     

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • Thanks a lot ...........

    These are useful ans.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply