sqlserver之指定字段显示固定的长度,这个平时显示数据的时候经常用到,但是记性不好,经常忘记。 故写于此,以便有用的时候捡起来。 这里举个例子,如有一个article表,里面有3个字段 展示的时候因为某些原因,标题,内容不能显示过长,这里设置不能超过11个
sqlserver之指定字段显示固定的长度,这个平时显示数据的时候经常用到,但是记性不好,经常忘记。
故写于此,以便有用的时候捡起来。
这里举个例子,如有一个article表,里面有3个字段
展示的时候因为某些原因,标题,内容不能显示过长,这里设置不能超过11个,其余用"..."代替,,内容文字不能超过30个,否则用"..."代替:
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
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!