views:

74

answers:

5

SELECT First 20 Chars of(ColName) from DB

Is this possible?

+5  A: 
SELECT left(ColName,20) AS First20 /*(Or 30 if we are looking at the title)*/
FROM YourTable
Martin Smith
+2  A: 
SUBSTRING(ColName, 1, 30)
reko_t
+1  A: 

Hi,

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!

Doug
+1  A: 
SELECT CONVERT(VARCHAR(30), ColName) from DB
Gabe
+1  A: 

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

smirkingman