Skip to content
Advertisement

T-SQL – compare strings char by char

I need to compare two strings character by character using T-SQL. Let’s assume i have twor strings like these:

Every time the character DO NOT match, I would like to increase the variable @Diff +=1. In this case the first three characters differ. So the @Diff = 3 (0 would be default value).

Thank you for all suggestions.

Advertisement

Answer

for columns in table you don’t want to use row by row approach, try this one:

=>sql fiddle demo

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement