What I'm trying to do is combine multiple columns into one. Say I have a table called Player
, this table contains multiple columns e.g name, team, goalie, left back, right back, center back , left midfield.... and description
.
The description
column would contain name
+ team
+ left back
, so description
would be Ronaldo - Madrid - Forward
. I can populate the description column when a player only has one position, but not for more than one position?
My SQL:
select
name, team, goalie,
leftback, rightback, centerback,
left midfield,
......,
name + ' - ' + team + ' - '+
CASE
WHEN goalie = 'yes' THEN 'Goalie'
WHEN leftback = 'yes' THEN 'Left Back'
WHEN rightback = 'yes' THEN 'Right Back'
WHEN centerback = 'yes' THEN 'Center Back'
.......
END AS Description
from
player
Output:
Ronaldo - Madrid - Forward
How can I get it to add more then one position, if the player has more than one?
Thanks