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. Convert or use expression in Sql select statement

Convert or use expression in Sql select statement

Scheduled Pinned Locked Moved Database
databasequestion
3 Posts 3 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.
  • I Offline
    I Offline
    indian143
    wrote on last edited by
    #1

    Hi, I have the following expression which either I want to execute in Select statement and get the result into a variable or some tables column anything is fine or I want to convert it into Select statements case anything which is possible please let me know, I need this friends.

    MCTR_DESCR == "Large" ? "LG" : MCTR_DESCR == "Midsize" ? "LG" : MCTR_DESCR == "Strategic Account" ? "LG" : MCTR_DESCR == "Strategic National" ? "LG" : MCTR_DESCR == "Large National" ? "LG" : MCTR_DESCR == "Small" ? "SG" : ISNULL([Copy of Column 11]) ? "SG" : [Copy of Column 11] == "" ? "SG" : LEFT([Copy of Column 11],1) == "X" ? "IFP" : [Copy of Column 11] == "W0051412" ? "Calpers" : [Copy of Column 11] == "W0051411" ? "Calpers" : "SG"

    Thanks in advance buddies, Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

    D Z 2 Replies Last reply
    0
    • I indian143

      Hi, I have the following expression which either I want to execute in Select statement and get the result into a variable or some tables column anything is fine or I want to convert it into Select statements case anything which is possible please let me know, I need this friends.

      MCTR_DESCR == "Large" ? "LG" : MCTR_DESCR == "Midsize" ? "LG" : MCTR_DESCR == "Strategic Account" ? "LG" : MCTR_DESCR == "Strategic National" ? "LG" : MCTR_DESCR == "Large National" ? "LG" : MCTR_DESCR == "Small" ? "SG" : ISNULL([Copy of Column 11]) ? "SG" : [Copy of Column 11] == "" ? "SG" : LEFT([Copy of Column 11],1) == "X" ? "IFP" : [Copy of Column 11] == "W0051412" ? "Calpers" : [Copy of Column 11] == "W0051411" ? "Calpers" : "SG"

      Thanks in advance buddies, Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      If you are using MS-SQL, check this out ... https://docs.microsoft.com/en-us/sql/t-sql/language-elements/case-transact-sql

      1 Reply Last reply
      0
      • I indian143

        Hi, I have the following expression which either I want to execute in Select statement and get the result into a variable or some tables column anything is fine or I want to convert it into Select statements case anything which is possible please let me know, I need this friends.

        MCTR_DESCR == "Large" ? "LG" : MCTR_DESCR == "Midsize" ? "LG" : MCTR_DESCR == "Strategic Account" ? "LG" : MCTR_DESCR == "Strategic National" ? "LG" : MCTR_DESCR == "Large National" ? "LG" : MCTR_DESCR == "Small" ? "SG" : ISNULL([Copy of Column 11]) ? "SG" : [Copy of Column 11] == "" ? "SG" : LEFT([Copy of Column 11],1) == "X" ? "IFP" : [Copy of Column 11] == "W0051412" ? "Calpers" : [Copy of Column 11] == "W0051411" ? "Calpers" : "SG"

        Thanks in advance buddies, Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

        Z Offline
        Z Offline
        ZurdoDev
        wrote on last edited by
        #3

        SELECT CASE WHEN MCTR_DESCR IN ('Large', 'Midsize') THEN 'LG' ELSE '' END ...

        etc. Just build it out. It's all pretty straightforward.

        There are two kinds of people in the world: those who can extrapolate from incomplete data. There are only 10 types of people in the world, those who understand binary and those who don't.

        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