How to put more than a fixed length of text to ... Said

Source: Internet
Author: User
Tags datetime table name
Once, a former colleague (a small mm) asked me a question: she wanted to display a list of posts in a Web page, but given that some of the headings were too long and aesthetically pleasing, you would want to refer to the styles on other sites and replace them with ellipses, but you didn't know how to do them. So think of me (alas, when I need to think of me, Woo ...) )

After getting the title, I decided to start from the database, write query statements to achieve, the results are as follows:

Description statement:

SELECT (Left (original field, number of digits) + ' ... ') as new field
From table name WHERE datalength (original field) > digits
UNION All
SELECT the original field as new field from table name WHERE datalength (original field) <= number of digits

It was later considered that access does not support the datalength () function, so it is Len (), but in this case, the Chinese text counts as one, not the original two digits.


Last written:
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) T emptable where kind= ' Activity Bulletin ' O

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.