I want to truncate a column to a max of 100 characters. How do you do this in SQL Server?
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.
SUBSTRING(myColumn, 1, 100)
See the docs: http://msdn.microsoft.com/en-us/library/ms187748.aspx
You can also use the LEFT() function.
LEFT(col, 100)
substring is the method: SUBSTRING ( value_expression ,start_expression , length_expression ) from the help.
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.