I am having an issue that i have to compare a string column with any value inserted by a user.
Values in column can be in any of formats below; and string cannot be more than 19 characters
00000000000
(000) 000-0000
000-000-0000
22222222222222
000 000 00000
000 000 0000
000-000-0000
000-000-00000
00 00 000 0000
000000000000
0000 0000 000
The problem is that the data we have contains so many formats and we cannot handle all while comparison in sqlserver as I have some limitation while querying that I can’t use any scalar function in where clause as it will disturb indexes and so as performance.
The only option I have is to handle it through C# code.
Can any one help me and guide me in making a generic function in C# which would handle all of the cases mentioned above and other which can be possible?
I would suggest to add new column that contains normalized value for the formatted value. The normalized value is simply the original value without the unimportant characters (space, bracket, etc.)
when user provide a new input, normalize it and compare it against the normalized value in the database using query.
When you save the data to the database, save both original value and normalized value.