Update : here Sql XOR :
only for a line with the letter len than 8
DECLARE @A VARCHAR(50)
DECLARE @B VARCHAR(50)
DECLARE @Pos INT
set @A='ABrC12@4'
set @B='ABrC1234'
SET @Pos=( select
case
when len(@A)<>LEN(@B) then -1
when @A=@B then 0
ELSE 1+PATINDEX('%[1-9]%',
CONVERT(varchar(max),cast(cast(CAST(@A AS varbinary) as BIGINT) ^
cast(CAST(@B AS varbinary) as BIGINT)
as varbinary ),2))/2
end)
Print @Pos
You can use a small nice result:
create FUNCTION [dbo].[fnFirstPosDif]
(
@Word as Nvarchar(70),
@Word2 as Nvarchar(70)
)
RETURNS INT
AS
BEGIN
declare @Strings2 TABLE
(
FirstPosDif INT
)
declare @FirstPosDif as int
;with C as
(
select @Word as Word,@Word2 as Word2 ,0 as Iteration
union all
select cast(substring(@Word,Iteration+1,1)as Nvarchar(70)) as Word,cast(substring(@Word2,Iteration+1,1)as Nvarchar(70)) as Word2,Iteration + 1 from C
WHERE Iteration < len(@Word) and cast(substring(@Word,Iteration+1,1)as Nvarchar(70))=cast(substring(@Word2,Iteration+1,1)as Nvarchar(70))
)
insert into @Strings2(FirstPosDif) select MAX(Iteration) as FirstPosDif from C
set @FirstPosDif=(select top 1 FirstPosDif from @Strings2)
return @FirstPosDif
END
source
share