开发者

How can I select the first 100 characters in SQL Server?

I want to truncate a column to a max of 100 characters. How do you do t开发者_开发知识库his in SQL Server?


Try this:

 SELECT LEFT (your_column, 100) FROM your_table 

Edit:

you can also try something like this:

  SELECT LEFT (your_column, LEN(your_column)-5) FROM your_table 

for say if you want to trim the last 5 characters from a record.


You can also use the LEFT() function.

LEFT(col, 100)


SUBSTRING(myColumn, 1, 100)

See the docs: http://msdn.microsoft.com/en-us/library/ms187748.aspx


substring is the method:

SUBSTRING ( value_expression ,start_expression , length_expression ) 

from the help.


SELECT SUBSTR(COLUMN_NAME, 1, LENGTH) FROM TABLENAME where LENGTH(COLUMN_NAME) > LENGTH

Ex:

SELECT SUBSTR(DESCRIPTION,1,100) FROM STOREDETAILS where LENGTH(DESCRIPTION)>100

For those records, with length less than 100, the actual value would be shown.

Otherwise, some databases induce blank characters in the resultant records.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜