Trailing Spaces Significant with the LIKE Keyword

Last reviewed: July 10, 1997
Article ID: Q118803
1.50 1.51 Windows kbprg

The information in this article applies to:

  The Microsoft Foundation Classes, included with:

    - Microsoft Visual C++ for Windows, versions 1.5 and 1.51

SUMMARY

The Microsoft Desktop ODBC drivers provided with Visual C++ versions 1.50 and 1.51 (the Simba driver) store trailing spaces in fixed-length text/character columns. This is important when using the LIKE keyword for filter clauses because trailing spaces are significant in LIKE. Therefore, to ensure pattern matching is successful against identifiers stored in fixed-length columns, a percent sign (%) should be added to the end of the search string.

MORE INFORMATION

Below are some examples of how to use the LIKE keyword in the m_strFilter string of a CRecordset object when using the ODBC drivers included with Visual C++. The two wildcard characters you can use are the percent sign (%) and the underscore (_). The percent sign can represent any number of characters. The underscore (_) can represent a single character.

Sample Code

   // This filter retrieves all records that start with "John".
   // Records such as "John", "Johnny", etc. will be returned.
   // Note that the % is necessary to retrieve "John" because
   // of the trailing spaces mentioned above.

   m_strFilter="Name LIKE 'John%'"

   // This filter retrieves only records where the field starts
   // with "J" and is followed by an additional character. Note
   // that a space is required after the underscore (_) to ensure that
   // only records with two characters are found. Using "J_" isn't
   // enough to find a record where the Name field is "Jo", for
   // example.

   m_strFilter="Name LIKE 'J_ %'"


Additional reference words: kbinf 1.50 1.51 2.50 2.51
KBCategory: kbprg
KBSubcategory: MfcDatabase
Keywords : MfcDatabase kbprg
Technology : kbMfc
Version : 1.50 1.51
Platform : Windows


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: July 10, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.