clear markdown compare help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2805432 fiddles created (40862 in the last week).

CREATE FUNCTION dbo.FindFirstDeff( @FirstStr VARCHAR(300), @SecondStr VARCHAR(300) ) RETURNS INT AS BEGIN DECLARE @Value INT = -1; WITH CTE AS ( SELECT 1 Num, @FirstStr Str1, @SecondStr Str2 UNION ALL SELECT Num + 1, Str1, Str2 FROM CTE WHERE Num < (SELECT CASE WHEN LEN(@FirstStr) > LEN(@SecondStr) THEN LEN(@FirstStr) ELSE LEN(@SecondStr) END) ) SELECT TOP 1 @Value =Num FROM CTE WHERE SUBSTRING(Str1, Num, 1) <> SUBSTRING(Str2, Num, 1) ORDER BY Num ASC OPTION (MAXRECURSION 300); RETURN(@Value); END
 hidden batch(es)


CREATE TABLE Strings(Str1 VARCHAR(300), Str2 VARCHAR(300)); INSERT INTO Strings VALUES ('Interesting', 'Interested'), ('Helping', 'Helped'), ('anything', 'unbelievable'), ('Staying', 'Stay'), ('abc', 'abc'); SELECT *, dbo.FindFirstDeff(Str1, Str2) Result FROM Strings;
Str1 Str2 Result
Interesting Interested 9
Helping Helped 5
anything unbelievable 1
Staying Stay 5
abc abc -1
 hidden batch(es)