I've put together a long statement that among other things selects different product names from a table. In my application, I want to limit the length of this name to 100 characters. So far, I've realized this by using LEFT(product_name, 100) within my query. However, I would like to add a '...' to the value in case the name is actually longer than 100 characters so the user knows that the actual value is a little bit longer than what he sees.
So if I only had 2 products in my database:
1: 'Awesome product'
2: 'Another totally awsome product that will make your life a lot better if you buy it because it is really awesome in many ways.'
The result should look like this:
1: 'Awesome product'
2: 'Another totally awsome product that will make your life a lot better if you buy it because it is rea...'
How can I do this with a simple SELECT query? My first instinct was to try something with IF:
SELECT LEFT(product_name, 100) + (IF LEN(product_name > 100) '...')
but that just gives me an error.
Aucun commentaire:
Enregistrer un commentaire