Monday, October 5, 2015

Underscore "_" is a wild card match character in MSSQL

Besides '%', underscore '_' is also a wild card match character in MSSQL. This can lead to some very subtle bug.

Say your table name has underscore in it, e.g., there are 2 tables my_Tablename and my_WeirdTablename. You find table using 'name like %_Tablename', then you will get both tables, instead of the first one. This leads to hidden bugs that are hard to identify.

To fix this issue, use this: 'name like %[_]tablename'. The '_' char is escaped by quoting it with brackets.

No comments:

Blog Archive

Followers