Once, a former colleague (a young girl) asked me a question: She wanted to display a list of article titles on a web page, but considering that some titles were too long and affected the appearance, she wanted to refer to other websites. The style, replace the text that exceeds the fixed length with ellipsis, but I don’t know how to implement it, so I thought of me (oh, you will only think of me when you need me, ugh...)
After getting the topic, I decided Start with the database and write a query statement to achieve it. The result is as follows:
Description statement:
SELECT (LEFT (original field, number of digits) '...') AS new field
FROM table name WHERE DATALENGTH (Original field)>Number of digits
UNION ALL
SELECT Original field AS New field FROM Table name WHERE DATALENGTH (Original field)<=Number of digits
Later, I considered that the DATALENGTH() function is not supported in ACCESS , so it was changed to LEN(), but in this case, the Chinese characters are also counted as one instead of the original two.
Finally written as:
select top 5 * from(
SELECT id,(LEFT([description],25) '...') AS descriptionx,kind,datetime, description, author, hit FROM [ xjx] WHERE len(description)>25
UNION ALL
SELECT id,description AS descriptionx,kind,datetime, description, author, hit FROM [xjx] WHERE len(description)<=25) TempTable where kind='Event Briefing' order by datetime "