DECLARE @str1 NVARCHAR(100)
DECLARE @str2 NVARCHAR(100)
DECLARE @len INT
SET @str1='蟆所鍵 螻 殊一蟲 レ焔讌'
SET @str2='蟆所鍵 螻 殊一蟲 レ焔讌 305-502'
SET @len = CASE WHEN LEN(@str1) > LEN(@str2) THEN LEN(@str1) ELSE LEN(@str2) END
;WITH Dumy
AS
(
SELECT 1 Seq
UNION ALL
SELECT Seq + 1 FROM Dumy
WHERE Seq + 1 <= @len
)
SELECT
COUNT(*) Cnt
, SUBSTRING(@str1, 1, COUNT(*)) str
FROM Dumy
WHERE Seq <= @len
AND SUBSTRING(@str1,Seq,1) = SUBSTRING(@str2,Seq,1)
OPTION (MAXRECURSION 0);
/*
Cnt str
----------- ---------------------------------------------
18 蟆所鍵 螻 殊一蟲 レ
*/