Although the two strings have different lengths and the characters are in a different order, they still have the same count of each alpha character. In your examples " abcdkazbmopdkubmgt " and "abckdazmbopkdumbgt" both have 2xAs, 3xBs, 1xC, 2xDs, 1xG, 2xKs, 2xMs, 1xO, 1xP, 1xT, 1xU and 1xZ (and no other alpha).Here's a function that will count each alpha in your string. Note, I'm a novice so there's probably a more efficient coding method...CREATE FUNCTION [dbo].[FN_CharID](@StringtoAssess VARCHAR(100))RETURNS char(26)ASBEGIN declare @position as int declare @ComparisonString as char(26) = 'abcdefghijklmnopqrstuvwxyz' declare @CurrentLetter as char(1) declare @cnt as int declare @tmpresult as char(26) set @position = 1 set @tmpresult = '00000000000000000000000000' while @position < 27 begin set @cnt = 0 set @CurrentLetter = substring(@ComparisonString,@position,1) WHILE charindex(@CurrentLetter,@StringtoAssess) > 0 BEGIN set @cnt = @cnt + 1 set @StringtoAssess = stuff(@StringtoAssess, charindex(@CurrentLetter, @StringtoAssess), 1, '') END set @tmpresult = stuff(@tmpresult, @position, 1, @cnt) set @position = @position + 1 end set @StringtoAssess = @tmpresult RETURN @StringtoAssessEND
Running the function across your strings both return "23120010002020110001100001". I hope this is useful.