Sunday, August 26, 2007

The difference of the LIKE SQL statements between MS Access and SQL Server

LIKE has been used widely in SQL Statements to filter or qualify certain records like this or that. The commonly used wild card characters in SQL Server are % and _, the former matches 0 or many characters; while the latter matches exactly one character. If you want to express NOT, you use ^.

If you copy and paste a SQL statement from SQL Server to MS Access with LIKE statement in it, you may not get exactly the same set of result. One of the reasons is the different symbols used in the LIKE statement.

In MS Access, * matches 0 or many characters; while ? matches extacly one. To express NOT, you use ! in MS Access.

One more note, if you want to match % or _ as is in LIKE statments in SQL Server, you will need to bracket them with a pair of square brackets [ and ]. Similarly, we need to squarely bracket * and ? to match them in the LIKE statements in MS Access.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home