Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Equivalent in MS Sql

Equivalent in MS Sql

Scheduled Pinned Locked Moved Database
questiondatabase
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hum Dum
    wrote on last edited by
    #1

    What is equivalent of MS Access IFF in MS Sql for this expression

    IIf([ID_SECTION]=1,1,IIf([ID_SECTION]=2,2,IIf([ID_SECTION]=3,[ID_Tariff_Gender],0)))

    Will it be like

    CASE WHEN [ID_SECTION]=1 THEN 1
    ELSE
    CASE WHEN [ID_SECTION]=2 then 2
    ELSE
    CASE WHEN [ID_SECTION] = 3 then [ID_Tariff_Gender] ELSE 0 END
    END
    END

    Is it correct ? Any comments !!

    G L 2 Replies Last reply
    0
    • H Hum Dum

      What is equivalent of MS Access IFF in MS Sql for this expression

      IIf([ID_SECTION]=1,1,IIf([ID_SECTION]=2,2,IIf([ID_SECTION]=3,[ID_Tariff_Gender],0)))

      Will it be like

      CASE WHEN [ID_SECTION]=1 THEN 1
      ELSE
      CASE WHEN [ID_SECTION]=2 then 2
      ELSE
      CASE WHEN [ID_SECTION] = 3 then [ID_Tariff_Gender] ELSE 0 END
      END
      END

      Is it correct ? Any comments !!

      G Offline
      G Offline
      Geoff Williams
      wrote on last edited by
      #2

      If you want to use a SQL CASE statement, then try the following:

      CASE [ID_SECTION]
      WHEN 1 THEN 1
      WHEN 2 THEN 2
      WHEN 3 THEN [ID_Tarriff_Gender]
      ELSE 0
      END

      1 Reply Last reply
      0
      • H Hum Dum

        What is equivalent of MS Access IFF in MS Sql for this expression

        IIf([ID_SECTION]=1,1,IIf([ID_SECTION]=2,2,IIf([ID_SECTION]=3,[ID_Tariff_Gender],0)))

        Will it be like

        CASE WHEN [ID_SECTION]=1 THEN 1
        ELSE
        CASE WHEN [ID_SECTION]=2 then 2
        ELSE
        CASE WHEN [ID_SECTION] = 3 then [ID_Tariff_Gender] ELSE 0 END
        END
        END

        Is it correct ? Any comments !!

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Hum Dum wrote:

        Is it correct ?

        Yes, it works.

        Hum Dum wrote:

        Any comments !!

        In this case, CASE is an overkill and an IF statement works perfectly well.

        S J 2 Replies Last reply
        0
        • L Lost User

          Hum Dum wrote:

          Is it correct ?

          Yes, it works.

          Hum Dum wrote:

          Any comments !!

          In this case, CASE is an overkill and an IF statement works perfectly well.

          S Offline
          S Offline
          SilimSayo
          wrote on last edited by
          #4

          I think it isn't overkill you're working on a select statement. [ID_SECTION] is probably a column name ---hint that a select statement is being used.

          1 Reply Last reply
          0
          • L Lost User

            Hum Dum wrote:

            Is it correct ?

            Yes, it works.

            Hum Dum wrote:

            Any comments !!

            In this case, CASE is an overkill and an IF statement works perfectly well.

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            Shameel wrote:

            In this case, CASE is an overkill and an IF statement works perfectly well.

            As a general statement I disgree with that. The IF is an acceptable alternative if CASE didn't exist but CASE exists specifically to deal with situations exactly like that. Given your statement what situation would be correct for CASE then?

            L 1 Reply Last reply
            0
            • J jschell

              Shameel wrote:

              In this case, CASE is an overkill and an IF statement works perfectly well.

              As a general statement I disgree with that. The IF is an acceptable alternative if CASE didn't exist but CASE exists specifically to deal with situations exactly like that. Given your statement what situation would be correct for CASE then?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              If you see the example, each nested CASE statement has only one WHEN clause, and this is where I recommended an IF clause which works exactly the same way and is more readable. There are, of course, situations where only CASE can be used and an IF cannot be used, like for example, in a SELECT statement.

              S J 2 Replies Last reply
              0
              • L Lost User

                If you see the example, each nested CASE statement has only one WHEN clause, and this is where I recommended an IF clause which works exactly the same way and is more readable. There are, of course, situations where only CASE can be used and an IF cannot be used, like for example, in a SELECT statement.

                S Offline
                S Offline
                SilimSayo
                wrote on last edited by
                #7

                The question refers to a column [ID_SECTION] which implies a select/insert/update/delete statement. [ID_SECTION] couldn't possibly be a variablle since it is not prefixed by '@'.

                1 Reply Last reply
                0
                • L Lost User

                  If you see the example, each nested CASE statement has only one WHEN clause, and this is where I recommended an IF clause which works exactly the same way and is more readable. There are, of course, situations where only CASE can be used and an IF cannot be used, like for example, in a SELECT statement.

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #8

                  Shameel wrote:

                  If you see the example, each nested CASE statement..,

                  Your statement wasn't clear but is still incorrect. For the example given it is misusing CASE. The correct solution is to use it correctly.

                  S 1 Reply Last reply
                  0
                  • J jschell

                    Shameel wrote:

                    If you see the example, each nested CASE statement..,

                    Your statement wasn't clear but is still incorrect. For the example given it is misusing CASE. The correct solution is to use it correctly.

                    S Offline
                    S Offline
                    SilimSayo
                    wrote on last edited by
                    #9

                    jschell wrote:

                    The correct solution is to use it correctly.

                    Most of our imports come from abroad! :laugh:

                    L 1 Reply Last reply
                    0
                    • S SilimSayo

                      jschell wrote:

                      The correct solution is to use it correctly.

                      Most of our imports come from abroad! :laugh:

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      SilimSayo wrote:

                      Most of our imports come from abroad!

                      Imports become necessary when locals lack quality and become unaffordable! ;-)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups