1

My Query looks like this

SELECT Distinct tm.teamid,tm.Team_Name,CONCAT_WS(' ',tu.FirstName+' '+tu.LastName) as Leader  FROM tblGameRelation tgr 
LEFT JOIN tblTeam tm ON tgr.teamid = tm.teamid AND tgr.gameid = 62
LEFT JOIN tblUsersRelation tur ON tgr.typeid=tur.typeid AND tur.usertypeid=1
LEFT JOIN tblUsers tu ON tu.UserId= tur.UserId 

My Problem is that when "Leader" field is Blank it should display "-" a Dash.I tried using if null but its not working, not sure if Mysql can do this, i know its possible in MSSQL SERVER

1 Answer 1

5

COALESCE() is your friend here:

COALESCE(CONCAT_WS(' ', tu.FirstName, tu.LastName), '-') AS leader

COALESCE() will pick the first expression, value or field given to it that isn't NULL and returns it.

Sign up to request clarification or add additional context in comments.

1 Comment

+1. Change the concatenation from CONCAT_WS(' ',tu.FirstName+' '+tu.LastName) to CONCAT_WS(' ', tu.FirstName, tu.LastName).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.