mereth mereth - 1 year ago 133
SQL Question

SQL truncate length of a string

i have a table programmers (id, name) in postgreSQL and i want to return names of all programmers and if a name has more than 12 characters i want to truncate it to exactly 12 characters, any ideas how can i do that?

Answer Source

Try this

select substring(name from 1 for 12) from your_table


Or the comment mentioned by @Prdp is a better alternative I think. Check the cost for both and use the one suits you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download