SQL Server之指定字段顯示固定的長(zhǎng)度
來源:程序員人生 發(fā)布時(shí)間:2014-02-18 13:05:57 閱讀次數(shù):3853次
SQLserver之指定字段顯示固定的長(zhǎng)度,這個(gè)平時(shí)顯示數(shù)據(jù)的時(shí)候經(jīng)常用到,但是記性不好,經(jīng)常忘記。
故寫于此,以便有用的時(shí)候撿起來。
這里舉個(gè)例子,如有一個(gè)Article表,里面有3個(gè)字段
展示的時(shí)候因?yàn)槟承┰颍瑯?biāo)題,內(nèi)容不能顯示過長(zhǎng),這里設(shè)置不能超過11個(gè),其余用"..."代替,內(nèi)容文字不能超過30個(gè),否則用"..."代替:
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 order by ArticleTime desc