Library code snippets

Access, VB and SQL Server wildcard characters

Visual Basic gives you several ways to provide pattern-matches in a
search string. Typically, you use pattern-matching characters for two
purposes: to search for strings in a VB application's GUI or variable,
or to look for items within a database, such as Access or SQL. When you
search for pattern matches in a database, however, depending on which
database you're using, different characters perform different matches.

The following list shows the different characters used by each database:

Required Match
Any single character
               Access/VB: ? SQLServer: _
Zero or more characters
               Access/VB: * SQLServer: %
Any single digit (0-9)
               Access/VB: # SQLServer: n/a
Any single character in charlist
               Access/VB: [charlist] SQLServer: [charlist]
Any single character not in charlist
               Access/VB: [!charlist] SQLServer: [^charlist]

Keep in mind that when you use Visual Basic's SQL Builder to create SQL
statements, it only accepts SQL Server pattern-matching characters--even
when you're pulling data from an Access database.

Comments

  1. 09 Nov 2007 at 09:23

    customer ids beginning with "C10" (can have any number of characters or no characters at all)
    17 found from select * from booking where [customer id num] like 'C10*'
    customer ids beginning with "C100" and one character
    16 found from select * from booking where [customer id num] like 'C100?'
    customer ids beginning with "C100" and two characters
    17 found from select * from booking where [customer id num] like 'C10??'
    customer ids beginning with "C100" and one character of 1,2 or 3
    10 found from select * from booking where [customer id num] like 'C100[123]'
    customer ids beginning with "C100" and one character which is not one of 1,2,3
    6 found from select * from booking where [customer id num] like 'C100[!123]'
    customer ids beginning with "C100" and one number
    16 found from select * from booking where [customer id num] like 'C100#'
    customer ids beginning with "C100" and two numbers
    17 found from select * from booking where [customer id num] like 'C10##'
  2. 17 Jan 2005 at 04:55
    i believe examples of the usage of these wildcards should be given in more real-life applications
  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Access, VB and SQL Server wildcard characters.

Leave a comment

Sign in or Join us (it's free).

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Related podcasts

  • Stack Overflow: Podcast #28

    This is the twenty-eighth episode of the StackOverflow podcast, where Joel and Jeff discuss Windows Azure, SQL Server 2008 full text search, Bayesian filtering, porn detection, and project management — among other things. Jeff met the inestimable Joey DeVilla aka Accordion Guy...

We'd love to hear what you think! Submit ideas or give us feedback