开发者

How to Select first 30 chars in a sql query?

开发者 https://www.devze.com 2023-01-19 12:17 出处:网络
SEL开发者_如何学GoECTFirst 20 Chars of(ColName) from DB Is this possible?SELECT left(ColName,20) AS First20 /*(Or 30 if we are looking at the title)*/

SEL开发者_如何学GoECT First 20 Chars of(ColName) from DB

Is this possible?


SELECT left(ColName,20) AS First20 /*(Or 30 if we are looking at the title)*/
FROM YourTable


SUBSTRING(ColName, 1, 30)


SELECT CONVERT(VARCHAR(30), ColName) from DB


Assuming that colname is VARCHAR, all the above will pad shorter strings to 20 characters.

If this is not what you want, then:

SELECT RTRIM(LEFT(colname, 20)) FROM DB


You can simply use one of the built in string functions. There are many variants so its best to see which one suits your situation best.

Enjoy!

0

精彩评论

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