I want to display after 8 characters, how to do that through substring
.
For contact name is amjad habib
, I want to display amjad hab...
.
SELECT SUBSTRING(contractname, 1, 8)
from contracts
where contractid = 613
I want to display after 8 characters, how to do that through substring
.
For contact name is amjad habib
, I want to display amjad hab...
.
SELECT SUBSTRING(contractname, 1, 8)
from contracts
where contractid = 613
This will cut your strings to a max length you can specify. The dots are only appended in case the string is to long and therefore truncated. Shorter strings are shown "as is":
DECLARE @tbl TABLE(TheName VARCHAR(100));
INSERT INTO @tbl VALUES('short'),('exactly8'),('something longer');
DECLARE @MaxLength INT=8;
SELECT TheName
,LEFT(TheName,@MaxLength) + CASE WHEN LEN(TheName)>@MaxLength THEN '...' ELSE '' END AS CutToMaxLength
FROM @tbl
The result
TheName CutToMaxLength
short short
exactly8 exactly8
something longer somethin...