开发者

MySQL Add dots (..) when shorted string

In an MySQL query I have this line in the SELECT statement:

IF(LENGTH(adr.klantnaam) > 20, LEFT(CONCAT(adr.klantnaam,'..'),20), adr.klan开发者_如何学Pythontnaam) AS klantnaam,

It shortens the text in the field bit it won't add the dots (..) at the end when the string is shortend.

How to change my code?


You need to do CONCAT(LEFT(adr.klantnaam,20),'..')

Otherwise you're adding the dots to the name (which you know is over 20 characters) before trimming, so it will always trim the dots off as well.

(If you want to end up with 20 characters, you could trim klantnaam to 18 chars, and then add the dots)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜