In a view, i have a column comments which may contain large string. I just want to select first 60 characters and append the '...' at the end of the selected string.
For selecting first 60 characters i have used following query:
select LEFT(comments, 60) as comments from myview
Now i want its processing as below:
Thanks
This question is related to
sql
sql-server-2008
tsql
To conditionally check the length of the string, use CASE
.
SELECT CASE WHEN LEN(comments) <= 60
THEN comments
ELSE LEFT(comments, 60) + '...'
END As Comments
FROM myView
Source: Stackoverflow.com