Professional Web Applications Themes

CASE or IF/ELSE - Microsoft SQL / MS SQL Server

Hello, I'm working on some procedures where I need conditional execution of some code. The main part of the procedure: DECLARE CUT_NO [int] --Get the current CUT_NO from underlying tables. select CUT_NO = ...... -- The problem: If CUT_NO = 0 I need to execute some code, and If CUT_NO <> 0 some other code IF (CUT_NO = 0) Begin select tmpLENGTH_MM = 1000 end ELSE Begin select tmpLENGTH_MM = 200 end END -- < I get an error on this line After this END, more statements occur that will be executed regardless of the value in CUT_NO Which approach ...

  1. #1

    Default CASE or IF/ELSE


    Hello,

    I'm working on some procedures where I need conditional execution of
    some code.

    The main part of the procedure:

    DECLARE
    CUT_NO [int]

    --Get the current CUT_NO from underlying tables.
    select CUT_NO = ......

    -- The problem: If CUT_NO = 0 I need to execute some code, and If
    CUT_NO <> 0 some other code

    IF (CUT_NO = 0)
    Begin
    select tmpLENGTH_MM = 1000
    end

    ELSE
    Begin
    select tmpLENGTH_MM = 200
    end
    END -- < I get an error on this line

    After this END, more statements occur that will be executed regardless
    of the value in CUT_NO


    Which approach shlud I use; CASE or IF THEN ELSE.

    Regards,

    Bent S.L



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Bent Guest

  2. #2

    Default Re: CASE or IF/ELSE

    Hi

    In general I would say that CASE is applicable if the subsequent statement
    issued are all simlar and can therefore be written as a single statement. If
    multiple statements are being execute I would look at creating separate
    procedures and using IF. Your example would probably be a candidate for a
    CASE statement, not in the setting of tmpLENGTH_MM but in the place where
    it is used.

    If you have time I would also look at the performance of each method and
    choose the most performant under the conditions and volumes that the
    application is to be used.

    John

    "Bent Lund" <no> wrote in message
    news:%phx.gbl... 


    John Guest

  3. #3

    Default Re: CASE or IF/ELSE

    Add...

    IF (CUT_NO = 0)
    BEGIN
    Begin
    select tmpLENGTH_MM = 1000
    end
    END
    ELSE
    BEGIN
    Begin
    select tmpLENGTH_MM = 200
    end
    END -- < I get an error on this line

    Bent Lund wrote: 

    Abel Guest

Similar Threads

  1. Replies: 112
    Last Post: December 9th, 05:46 PM
  2. Is there a way to convert lower case text to upper case text in PHP?
    By tanas@ing.com.au in forum PHP Development
    Replies: 3
    Last Post: December 11th, 06:12 AM
  3. #23026 [Com]: Make Zend case-sensitive (classes, functions, remove case-insensitive)
    By nvivo at mandic dot com dot br in forum PHP Development
    Replies: 0
    Last Post: October 19th, 12:17 PM
  4. How can I use case statement in my case, if I can??
    By Ricky in forum Microsoft SQL / MS SQL Server
    Replies: 3
    Last Post: August 14th, 05:44 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139