Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return first N characters of string

I need to select a shortened version of a field from a SQL Server table to use in a drop down list.

This field has to be limited to twenty characters. If the field has more than twenty characters, it should display the first twenty; if it has less than twenty characters, it should display the whole string.

How do I do this?

like image 238
reefes Avatar asked Dec 16 '09 21:12

reefes


2 Answers

You can use the LEFT command.

like image 81
TLiebe Avatar answered Oct 06 '22 01:10

TLiebe


Try left(sting_field,20) or right(sting_field,20)

like image 40
adopilot Avatar answered Oct 05 '22 23:10

adopilot