概述
SQLserver之指定字段显示固定的长度,这个平时显示数据的时候经常用到,但是记性不好,经常忘记。
故写于此,以便有用的时候捡起来。
这里举个例子,如有一个Article表,里面有3个字段
展示的时候因为某些原因,标题,内容不能显示过长,这里设置不能超过11个,其余用"..."代替,内容文字不能超过30个,否则用"..."代替:
:
![](http://images.cnblogs.com/outliningindicators/contractedblock.gif)
![expandedblockstart.gif](http://images.cnblogs.com/outliningindicators/expandedblockstart.gif)
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
1
select ArticleTitle=
2 case when len(ArticleTitle)>11
3 then substring(ArticleTitle,0,11)+'...'
4 else ArticleTitle
5 end
6 ,ArticleTime,ArticleContent=
7 case when len(ArticleContent)>11
8 then substring(ArticleContent,0,33)+'...'
9 else ArticleContent
10 end
11 from Article order by ArticleTime desc
2 case when len(ArticleTitle)>11
3 then substring(ArticleTitle,0,11)+'...'
4 else ArticleTitle
5 end
6 ,ArticleTime,ArticleContent=
7 case when len(ArticleContent)>11
8 then substring(ArticleContent,0,33)+'...'
9 else ArticleContent
10 end
11 from Article order by ArticleTime desc
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16436858/viewspace-623443/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/16436858/viewspace-623443/
最后
以上就是听话大侠为你收集整理的SQL server之指定字段显示固定的长度的全部内容,希望文章能够帮你解决SQL server之指定字段显示固定的长度所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复