The below code very useful for me when i was searching some requirement as per job.
Then i got this code from stack overflow. In this below scenario one string is matching with another if it is matched then return something else something.
declare @s1 varchar(50) = 'my word is my power'declare @s2 varchar(50) = 'my power is my word'
declare @t1 table (word varchar(50))
while len(@s1)>0
begin
if (CHARINDEX(' ', @s1)>0)
begin
insert into @t1 values(ltrim(rtrim(LEFT(@s1, charindex(' ', @s1)))))
set @s1 = LTRIM(rtrim(right(@s1, len(@s1)-charindex(' ', @s1))))
end
else
begin
insert into @t1 values (@s1)
set @s1=''
end
end
declare @t2 table (word varchar(50))
while len(@s2)>0
begin
if (CHARINDEX(' ', @s2)>0)
begin
insert into @t2 values(ltrim(rtrim(LEFT(@s2, charindex(' ', @s2)))))
set @s2 = LTRIM(rtrim(right(@s2, len(@s2)-charindex(' ', @s2))))
end
else
begin
insert into @t2 values (@s2)
set @s2=''
end
end
select case when exists(SELECT * FROM @t1 EXCEPT SELECT * FROM @t2) then 'are not' else 'are equal' end
No comments:
Post a Comment