我在SQL Server中有很大的字符串。我想将该字符串截断为10或15个字符
原始字符串
this is test string. this is test string. this is test string. this is test string.
所需字符串
this is test string. this is ......
发布于 2013-03-01 01:58:06
如果只想返回长字符串的几个字符,可以使用:
select
left(col, 15) + '...' col
from yourtable
这将返回字符串的前15个字符,然后将...
连接到字符串的末尾。
如果你想确保小于15的字符串不会得到...
,那么你可以使用:
select
case
when len(col)>15
then left(col, 15) + '...'
else col end col
from yourtable
发布于 2013-03-01 02:24:05
您可以使用
LEFT(column, length)
或
SUBSTRING(column, start index, length)
发布于 2015-03-25 17:14:37
您还可以使用Cast()操作:
Declare @name varchar(100);
set @name='....';
Select Cast(@name as varchar(10)) as new_name
https://stackoverflow.com/questions/15142356
复制相似问题