Saturday, November 20, 2010

SQL Query vs Microsoft Access Query

There are subtle differences in the way that you write queries depending on if you use SQL Server or Microsoft Access to write your query.  One difference is that Microsoft Access uses the pound(#) sign for a date and SQL Server uses an apostrophe(') for a date. 

SQL Server Example:  WHERE Date_Found BETWEEN '11/1/2010' and '11/20/2010'
Microsoft Access Example:  WHERE Date_Found BETWEEN #11/1/2010# and #11/20/2010#

Another difference is with the LIKE command.  When you use the LIKE command with SQL Server, you would use the percent(%) sign.  With Microsoft Access, you would use the asterick(*).

SQL Server Example:  WHERE Example LIKE '%this%'
Microsoft Access Example:  WHERE Example LIKE "*this*"

As you can see, Microsoft Access utilizes quotes(") for strings and SQL Server utilizes apostrophes(') for strings.  These differences can cause errors, and even though you may think you are writing the correct query, you are actually not.

No comments:

Post a Comment