127

SQLServerに大きな文字列があります。その文字列を10文字または15文字に切り捨てたい

元の文字列

this is test string. this is test string. this is test string. this is test string.

希望の文字列

this is test string. this is ......
4

6 に答える 6

189

長い文字列の数文字のみを返したい場合は、次を使用できます。

select 
  left(col, 15) + '...' col
from yourtable

SQL Fiddle with Demoを参照してください。

これにより、文字列の最初の 15 文字が返さ...れ、最後に が連結されます。

15 未満の文字列が取得されないようにしたい場合は、...次を使用できます。

select 
  case 
    when len(col)>15
    then left(col, 15) + '...' 
    else col end col
from yourtable

デモで SQL Fiddle を参照してください

于 2013-02-28T17:58:06.283 に答える
44

使用できます

LEFT(column, length)

また

SUBSTRING(column, start index, length)
于 2013-02-28T18:24:05.047 に答える