1

I'm running this code on SQL2008 to remove non-aphanumerical characters from strings :

snip from my function stralpha:
...
Set @KeepValues = '%[^a-z0-9]%'
While PatIndex(@KeepValues, @Temp) > 0
      Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '')
Return @Temp
...

It has worked flawlessly, but now I've got at string with the part 'AA' in it :

SELECT dbo.stralpha('10AAV2');

which returns

10AV2

and I expected

10AAV2

I've tried with other repeating characters without problems - but can reproduce with aa as well.

Does anyone have a hint troubleshoot?

  • It seems that the problem is related to [^a-z0-9] matching AA when I'm not expecting it to. For now, I've made a workaround to loop through each character and check that. It must, however, be a very inefficient solution. – Stig Meyer Jensen May 24 '15 at 11:13

0 Answers0