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. SQL - How to Create a New column based on values from existing column

SQL - How to Create a New column based on values from existing column

Scheduled Pinned Locked Moved Database
questiondatabasecollaborationhelptutorial
3 Posts 2 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.
  • C Offline
    C Offline
    CodeWeaker
    wrote on last edited by
    #1

    I have an tables as below

    Team Country Gender
    A US Male
    B UK Female
    A France Male
    B Canada Female
    A US Male

    My Requirement: Based on the values in the table above I need a NEW Column named Selection with below criteria If Team A + US + Male then 'SELECTED', If Team A + France + Male then 'Re-Apply' If Team A + France + Male then 'Re-Apply' If Team B + UK + Female then 'Rejected' If Team B + Canada + Female then 'SELECTED' So I want my output to look like this.

    Team Country Gender Selection
    A US Male SELECTED
    B UK Female Rejected
    A France Male Re-Apply
    B Canada Female SELECTED
    A Germany Male Re-Apply

    How Do I do that in MS SQL ? I tried using a function but for some reason it doesn't seems to work. Can you please help ? Thanks in Advance.

    M C 2 Replies Last reply
    0
    • C CodeWeaker

      I have an tables as below

      Team Country Gender
      A US Male
      B UK Female
      A France Male
      B Canada Female
      A US Male

      My Requirement: Based on the values in the table above I need a NEW Column named Selection with below criteria If Team A + US + Male then 'SELECTED', If Team A + France + Male then 'Re-Apply' If Team A + France + Male then 'Re-Apply' If Team B + UK + Female then 'Rejected' If Team B + Canada + Female then 'SELECTED' So I want my output to look like this.

      Team Country Gender Selection
      A US Male SELECTED
      B UK Female Rejected
      A France Male Re-Apply
      B Canada Female SELECTED
      A Germany Male Re-Apply

      How Do I do that in MS SQL ? I tried using a function but for some reason it doesn't seems to work. Can you please help ? Thanks in Advance.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Create a view and use a case statement to determine the value of Selected. However what value are you going to put when the country = Canada and the Gender is male?

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • C CodeWeaker

        I have an tables as below

        Team Country Gender
        A US Male
        B UK Female
        A France Male
        B Canada Female
        A US Male

        My Requirement: Based on the values in the table above I need a NEW Column named Selection with below criteria If Team A + US + Male then 'SELECTED', If Team A + France + Male then 'Re-Apply' If Team A + France + Male then 'Re-Apply' If Team B + UK + Female then 'Rejected' If Team B + Canada + Female then 'SELECTED' So I want my output to look like this.

        Team Country Gender Selection
        A US Male SELECTED
        B UK Female Rejected
        A France Male Re-Apply
        B Canada Female SELECTED
        A Germany Male Re-Apply

        How Do I do that in MS SQL ? I tried using a function but for some reason it doesn't seems to work. Can you please help ? Thanks in Advance.

        C Offline
        C Offline
        CodeWeaker
        wrote on last edited by
        #3

        Hi there, I was able to sort this out using an function. Funtion takes the values from each row and calculates my requirement and populated as separate column.

        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