SQL查询中的子串方法

时间:2012-11-07 09:04:01

标签: sql sql-server-2005

这是我用来减少角色长度的查询。

这些是一些示例char(“有关可以的有效SQL Server 2005数据类型的详细信息...是一个整数,指定子字符串的起始位置.start可以是bigint类型。”)

如果我给substring定义长度最多15。其余的char应该这样显示(...)

我的SQL查询就是这个......

select substring('For more information about the valid SQL Server 2005 data types that can be ... Is an integer that specifies where the substring starts. start can be of type bigint.',0,15) from Admin
例如:它应该显示为

For more information about the valid SQL Server 2005 data.

5 个答案:

答案 0 :(得分:2)

select substring('For more information about the valid SQL Server 2005 data types that can be ... Is an integer that specifies where the substring starts. start can be of type bigint.',0,58)+'.........' 

答案 1 :(得分:0)

你的意思是:

select Left('For more information about the valid SQL Server 2005 data', 15)+'...'

指定要显示为系统定义函数LEFT的第二个参数的字符数。

答案 2 :(得分:0)

你可以使用这样的东西:

    select substring('For more information about the valid SQL Server 2005 data types that can be ... Is an integer that specifies where the substring starts. start can be of type bigint.',0,15)+replicate('.', 25) 
from Admin 

答案 3 :(得分:0)

如果你想让输出像这样

First_15_letters_ ... _Last_15_letters

然后这是一种方法

select 
substring('For more information about the valid SQL Server 2005 data types that can be ... Is an integer that specifies where the substring starts. start can be of type bigint.',0,15) 

+ '...' + 

right('For more information about the valid SQL Server 2005 data types that can be ... Is an integer that specifies where the substring starts. start can be of type bigint.',15)

from Admin;

答案 4 :(得分:0)

Please, not down from here :
=======================================================
  select substring('For more information about the valid SQL Server 2005 data types that
    can    be ... Is an integer that specifies where the substring starts. start can 
    be of type bigint.',0,15) 
--Not need "from Admin"
===============================================================
select substring(colname,0,15) from Admin
--"from Admin" Need when columnname is required