2012-11-07 17 views
3

這是我用來減少字符長度的查詢。SQL查詢中的子串方法

這些都是一些例子字符(「關於有效的SQL Server 2005數據類型,可以是...更多信息是一個整數,指定字符串的開始。開始可能是bigint類型。」)

如果我給substring修復長度達15。炭的其餘部分應表現出這樣的方式(...)

我的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. 
+0

「剩下的應該表現得像......」,這是真的還是你想縮短弦? **什麼不行?** –

+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)+'.........' 
0

您的意思是這樣的:

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

指定的字符數被示出爲系統定義的函數LEFT的第二個參數。

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)+replicate('.', 25) 
from Admin 
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) 

+ '...' + 

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; 
的一種方式
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