SQL - How to Create a New column based on values from existing column
-
I have an tables as below
Team Country Gender
A US Male
B UK Female
A France Male
B Canada Female
A US MaleMy 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-ApplyHow 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.
-
I have an tables as below
Team Country Gender
A US Male
B UK Female
A France Male
B Canada Female
A US MaleMy 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-ApplyHow 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.
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
-
I have an tables as below
Team Country Gender
A US Male
B UK Female
A France Male
B Canada Female
A US MaleMy 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-ApplyHow 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.
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.