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. IF Else Statement in SQL Statment

IF Else Statement in SQL Statment

Scheduled Pinned Locked Moved Database
databasequestion
6 Posts 6 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
    HatakeKaKaShi
    wrote on last edited by
    #1

    SELECT column1, column2, if (column3 = 0) begin 'Z', end else begin 'C', end FROM table1 Is it possible that i can do it this way?

    KaKaShi HaTaKe

    A N M K 4 Replies Last reply
    0
    • H HatakeKaKaShi

      SELECT column1, column2, if (column3 = 0) begin 'Z', end else begin 'C', end FROM table1 Is it possible that i can do it this way?

      KaKaShi HaTaKe

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Now, a question for YOU. Which takes longer, typing it in to CP and waiting for a reply, or typing in into query analyser and running it? A clue, try the CASE statement.

      Bob Ashfield Consultants Ltd

      P 1 Reply Last reply
      0
      • H HatakeKaKaShi

        SELECT column1, column2, if (column3 = 0) begin 'Z', end else begin 'C', end FROM table1 Is it possible that i can do it this way?

        KaKaShi HaTaKe

        N Offline
        N Offline
        nelsonpaixao
        wrote on last edited by
        #3

        explain your:confused:self!!!!

        nelsonpaixao@yahoo.com.br trying to help & get help

        1 Reply Last reply
        0
        • A Ashfield

          Now, a question for YOU. Which takes longer, typing it in to CP and waiting for a reply, or typing in into query analyser and running it? A clue, try the CASE statement.

          Bob Ashfield Consultants Ltd

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #4

          Ashfield wrote:

          A clue, try the CASE statement.

          A fine clue, that is :)

          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

          1 Reply Last reply
          0
          • H HatakeKaKaShi

            SELECT column1, column2, if (column3 = 0) begin 'Z', end else begin 'C', end FROM table1 Is it possible that i can do it this way?

            KaKaShi HaTaKe

            M Offline
            M Offline
            mstfnoor 0
            wrote on last edited by
            #5

            SELECT column1, column2, CASE WHEN (column3 = 0) THEN 'Z' ELSE 'C' END FROM table1 ------------- Mostafa Noor Egypt

            1 Reply Last reply
            0
            • H HatakeKaKaShi

              SELECT column1, column2, if (column3 = 0) begin 'Z', end else begin 'C', end FROM table1 Is it possible that i can do it this way?

              KaKaShi HaTaKe

              K Offline
              K Offline
              Kevin Horgan
              wrote on last edited by
              #6

              Hi there, I think you might want to use a CASE statement. Not sure which database system you are using but it would look something like this... SELECT column1, column2, CASE column3 WHEN 0 THEN 'Z' ELSE 'C' END FROM table1 Cheers, Kevin

              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