The specified field in SQL Server displays a fixed length

Source: Internet
Author: User

The specified field in SQL Server displays a fixed length, which is often used when displaying data, but has a bad memory and often forgets.

So write this so that when it is useful, pick it up.

For example, there is a article table with 3 fields in it.

Show the time for some reason, the title, content can not be shown too long, here can not set more than 11, the rest with "..." instead of content text can not be more than 30, otherwise use "..." instead:

Select articletitle=

case when Len (articletitle) >11

Then substring (articletitle,0,11) + ' ... '

else ArticleTitle

End

, articletime,articlecontent=

case when Len (articlecontent) >11

Then substring (articlecontent,0,30) + ' ... '

else articlecontent

End

From Article to Articletime desc

Related Article

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.