Can I Use If Condition In View

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anubha12
    New Member
    • Mar 2007
    • 4

    Can I Use If Condition In View

    HiiiALL..
    I AM CREATING A VIEW AND USE IN THIS IF AND ELSE CONDITION.
    THIS SYNTAX IS NOT WORKING PROPERLY..CAN USE OR NOT??
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    No, you can not use IF condition in a view.
    There are so many other ways to do it.


    Thank you.

    Comment

    • anubha12
      New Member
      • Mar 2007
      • 4

      #3
      Originally posted by iburyak
      No, you can not use IF condition in a view.
      There are so many other ways to do it.


      Thank you.
      thank u sir for reply
      u say that there is many ways.
      so sir what is the other way..

      Comment

      • iburyak
        Recognized Expert Top Contributor
        • Nov 2006
        • 1016

        #4
        1. You can create a table function.
        2. You can return result of a stored procedure.
        3. You can use where condition on existing view.
        4. You can use Case in select statements of a view which is in many cases is almost the same as IF ELSE.
        5. You can create different views and use them depend on a conditions like.
        Create view View_StoredProc s
        AS
        select name from sysobjects where type like 'p'

        Create view View_Tables
        AS
        select name from sysobjects where type like 'u'

        and more.....

        Comment

        • leniel
          New Member
          • Nov 2007
          • 1

          #5
          Hi iburyak,

          I've used the case statement and it is working as expected here.

          Thanks for the excellent explanation.

          Comment

          • iburyak
            Recognized Expert Top Contributor
            • Nov 2006
            • 1016

            #6
            Originally posted by leniel
            Hi iburyak,

            I've used the case statement and it is working as expected here.

            Thanks for the excellent explanation.
            You are welcome.
            For generic question I had a generic answer.
            I am glad you were able to get some info out of it... :)
            Good Luck.

            Comment

            Working...