declare @str1 VARCHAR(20) = '123'
declare @str2 VARCHAR(20) = '12345'
SELECT CASE WHEN EXISTS (
SELECT 1
FROM master.dbo.spt_values V
WHERE V.type='P'
AND V.number BETWEEN 1 AND LEN(@str1)
AND CHARINDEX(SUBSTRING(@str1, v.number, 1), @str2) = 0
) THEN 0
ELSE 1
END