-- strings to compareDECLARE @s1 varchar(8000)='diner', @s2 varchar(8000)='dinerr';DECLARE @ld int=ABS(LEN(@s1)-LEN(@s2));IF ((@s1=@s2) OR ((ISNULL(LEN(@s1)*LEN(@s2),0)=0))) BEGIN GOTO LD END; DECLARE @minlen int=CASE WHEN LEN(@s1)>LEN(@s2) THEN LEN(@s2) ELSE LEN(@s1) END; ;WITH nums(n) AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) FROM [master].dbo.spt_values Tally), matrix AS (SELECT SUBSTRING(@s1,n,1) s1, SUBSTRING(@s2,n,1) s2 FROM nums WHERE n<=@minlen) SELECT @ld+=COUNT(*) FROM matrix WHERE s1<>s2;LD:SELECT @ld AS LD;