How to write if else condition in Procedure

  • Dear All,

    In the below procedure,i want to little bit modification.

    I am a Java J2ee professional.I dont know about pl/sql program.

    Please help me in my procedure.

    Suppose It will check a condition from the table let say test_abc.

    If "select abc from test_abc" query returns "Inv" then some select statement like

    Select

    'Active' AS DISPLAY,

    '0' AS VALUE

    Union

    Select

    'Archived' AS DISPLAY,

    '1' AS VALUE

    else

    Select

    'Active' AS DISPLAY,

    '0' AS VALUE

    Union

    Select

    'Archived' AS DISPLAY,

    '1' AS VALUE

    Select

    'Rejected' AS DISPLAY,

    '1 AND W_CURRENT_STEP = DELETE' AS VALUE

    USE [TEST_XYZ]

    GO

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER OFF

    GO

    CREATE Proc [dbo].[searchGetStatusValues]

    @LOGIN_NAME VarChar(20) = ''

    AS SET NOCOUNT ON

    Select

    'Active' AS DISPLAY,

    '0' AS VALUE

    Union

    Select

    'Archived' AS DISPLAY,

    '1' AS VALUE

    Union

    Select

    'Both' AS DISPLAY,

    '' AS VALUE

    Union

    Select

    'Rejected' AS DISPLAY,

    '1 AND W_CURRENT_STEP = DELETE' AS VALUE

    Thanks in advance.

    Regards,

    Sumanta Panda

  • Hi try This

    DECLARE @Value VARCHAR(50)

    select @Value=abc from test_abc WHERE LoginName=@LOGIN_NAME

    IF @Value='Inv'

    BEGIN

    Select

    'Active' AS DISPLAY,

    '0' AS VALUE

    Union

    Select

    'Archived' AS DISPLAY,

    '1' AS VALUE

    END

    ELSE

    BEGIN

    Select

    'Active' AS DISPLAY,

    '0' AS VALUE

    Union

    Select

    'Archived' AS DISPLAY,

    '1' AS VALUE

    Select

    'Rejected' AS DISPLAY,

    '1 AND W_CURRENT_STEP = DELETE' AS VALUE

    END

    Thanks
    Parthi

  • the general construct in t-SQL is

    If (condition)

    begin

    true statements

    end

    else

    begin

    false statements

    end

    http://msdn.microsoft.com/en-us/library/ms182717%28SQL.90%29.aspx

  • I highly recommend you download the latest copy of SQL Server 2005 Books Online, install it, and get very familiar with it. It is a wonderful resource!!!

    Here is the construct from BOL:

    IF Boolean_expression

    { sql_statement | statement_block }

    [ ELSE

    { sql_statement | statement_block } ]

    Here is the BOL link: ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/676c881f-dee1-417a-bc51-55da62398e81.htm

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

  • I wouldn't download the BOL

    use the lightweight online version

    http://msdn.microsoft.com/en-us/library/ms130214.aspx

    I would avoid the (extremely bad) microsoft local help system

    the online versions are much quicker

    that is unless you like:

    - waiting up to 60 seconds for it to start up

    - waiting 30 minutes for a re-indexing (again and again)

    - multigigabytes of data you will never read on your boot drive

    - a search system that is much slower than google

    - being forced to use internet explorer

  • doobya (12/3/2009)


    I wouldn't download the BOL

    use the lightweight online version

    http://msdn.microsoft.com/en-us/library/ms130214.aspx

    I would avoid the (extremely bad) microsoft local help system

    the online versions are much quicker

    that is unless you like:

    - waiting up to 60 seconds for it to start up

    - waiting 30 minutes for a re-indexing (again and again)

    - multigigabytes of data you will never read on your boot drive

    - a search system that is much slower than google

    - being forced to use internet explorer

    What a bunch of mis/bad information there!

    1) Who cares if it takes 60 sec to start up? If it isn't open already (my copy is NEVER closed), start it, go do something else for 59 sec, come back - if you are in that much of a tizzy to be productive.

    2) No idea what you are speaking of there. I have NEVER had any such action occur that keeps my BOL copies from being available 24/7.

    3) How about 121MB for 2005 and 128MB for 2008 BOL. Oh, and you can put them wherever you like. Mine are on my D drive.

    4) You can configure what resources are searched, which could be why you say it is slower than google. Besides, I almost NEVER search BOL. I use the index, which is instantaneous and gets me what I need 98+% of the time.

    5) Not everyone has an internet connection all the time.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

  • 1) the download size is 144mb

    2) then it decompresses

    3) then it calculates the indexes

    4) the indexes are stored in the windows folder

    5) every product that integrates with microsoft help system (msdn, bol, winsdk, dxsdk, evc, 3rd party ones) require a very long, high cpu reindexing of EVERYTHING (merging)

    6) that means everytime you install, reinstall, uninstall you have to wait for the "merging"

    6a) if you hit F1 this merging operation will lock up the application you were using until it finishes - if you force a shutdown the help system gets corrupted - how often do I hit F1 and then "oh no here we go again - cannot work"

    7) on my machine the microsoft help indexes alone are 2.5GB in the Windows folder (not including the help content itself)

    7a) that is bigger than my Docs and Settings and Program Files folders combined!

    8) when the help system gets corrupted it can be nigh on impossible to fix it

    if the only ms help you have on your machine is BOL then you might not notice the downsides

  • I too have get incredibly ticked off with software entities (almost all of them unfortunately) putting unwanted crap in the boot partition!!! :angry:

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

Viewing 8 posts - 1 through 7 (of 7 total)

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