-2

I am trying to concatenate values from multiple fields using concat_ws. One of the fields (is_logged) contains only the values 0 or 1. I want to concatenate yes if the value of is_logged field is 1 and no otherwise.

E.g. - concat_ws('', month,'-', year, ',Logged-', is_logged) info

Current output - Dec - 2020,Logged-1

Expected output - Dec - 2020,Logged-Yes

How can this be achieved? Thanks!

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Ira
  • 547
  • 4
  • 13

2 Answers2

1

can be different in different dbms but you can do this:

select concat_ws('',month,'-',year,',Logged-',case is_logged when 1 then 'yes' else 'no' end) info
from yourtable
eshirvana
  • 23,227
  • 3
  • 22
  • 38
0

I got this working based on this answer -

concat_ws('', month,'-', year, ',Logged-',IFNULL(ELT(FIELD(is_logged,1),'Yes'),'No')) info
eshirvana
  • 23,227
  • 3
  • 22
  • 38
Ira
  • 547
  • 4
  • 13