Using Apostrophes and Quotation Marks with SQL WHERE Clause

Last reviewed: October 31, 1994
Article ID: Q46020
The information in this article applies to:
  • Q+E for Microsoft Excel for Windows, version 2.1

SUMMARY

When using character constants in an SQL WHERE clause, you must use a set of apostrophes or quotation marks around the string constant. If one apostrophe or quotation mark occurs within the string, make sure there is a second, matching one at the point the first one occurs.

More Information:

If a file is named TEST.DBF and the data is in a field named SAMPLE, the following statement selects all of the entries with SQL:

   SELECT SAMPLE
   FROM TEST.DBF

The following statement selects those occurrences of the string that don't uses:

   SELECT SAMPLE
   FROM TEST.DBF
   WHERE SAMPLE='don''t'

The following statement selects those occurrences of the string that "false" uses:

   SELECT SAMPLE
   FROM TEST.DBF
   WHERE SAMPLE="""false"""

Note: The inner set of quotation marks are part of the string and appear in the file.

Make sure to use quotation marks if the string has quotation marks in or around it. The same rule applies to apostrophes.


KBCategory: kbother
KBSubcategory:

Additional reference words: 2.1 2.10


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 31, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.