Can I use whitespace to add new wildcard?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dascott20
    New Member
    • Jul 2010
    • 9

    Can I use whitespace to add new wildcard?

    Hello,

    I am working on a web page that queries a microsoft access database for our library using wildcards, I have set up the queries using the CONTAINS expression, like so
    Code:
                    '"Select Command" Value part 1
                    Dim SelStat As String = "SELECT [Full Title] AS Full_Title, [Author List] AS Author_List, [Title Call Number] AS Title_Call_Number, [Series] AS Series, [Location] AS Location FROM [Library]"
                    '"Select Command" Value part 2
                    Dim Where As String = " WHERE"
                    '(Part 3 is set further below)
                    '"Select Command" Value part 4
                    Dim Order As String = "ORDER BY [Title Call Number]"
    '...
     whereStatement = " CONTAINS (([Full Title], '%' + ? + '%')"
    My problem is that the CONTAINS statement acts no differently than the LIKE statement in that the words have to be in order to include spaces and commas.
    What I want to do is make it so that multiple words in the same text box will create new wildcards in my SQL statement
    (eg. text box= "word1 word2 word3" will translate into SQL as
    Code:
     whereStatement = " CONTAINS (([Full Title], 'word1' AND 'word2', AND 'word3')"
    using the space between the words to separate variables rather than read as a separate character.

    Any help would be much appriciated.
  • orangeCat
    New Member
    • Dec 2007
    • 83

    #2
    What do your Access database tables look like? ie What is the Structure?
    I have not seen the CONTAINS in Access SQL. Are you sure it is available?

    Comment

    • colintis
      Contributor
      • Mar 2010
      • 255

      #3
      orangeCat is right, there's no CONTAINS function in Access. The way to work around is using LIKE function.
      Code:
      whereStatement = _
      "[Full Title] LIKE '*Word1*'
      AND [Full Title] LIKE '*Word2*'
      AND [Full Title] LIKE '*Word3*'"

      Comment

      • dascott20
        New Member
        • Jul 2010
        • 9

        #4
        orangeCat is correct the contains statement isn't available in MS Access however the data tables and queries are being set up in MS Visual Studios 2010 (more specifically I'm using VB to dynamically change them.) and are using Access for the information only. I have the CONTAINS statements set up and they do work, but without further defining them they act the same way as the LIKE statement does.

        For clarification: I am not looking for the type of statement necessarily. What I would like to know how to do is code my page so that wherever a user hits the space bar or uses a comma in the textbox to search, the page will treat the next word as a separate parameter rather than one full string.

        Comment

        Working...