+ Reply to Thread
Results 1 to 22 of 22

MS Query - Wildcard 'Like' with a parameter

  1. #1
    Registered User
    Join Date
    01-15-2009
    Location
    Hertfordshire, England
    MS-Off Ver
    Excel 2007
    Posts
    9

    MS Query - Wildcard 'Like' with a parameter

    Hi there,
    This is my first post so appologies if it's in the wrong forum.
    I have an MS Query that downloads data from a SQL server. One of the fields contains (amonst other things) an agreement number and I want to be able to select the agreement number at run time.

    The criteria I'm using looks like this:
    Like ('%' + [Enter Agreement No] + '%')
    The query runs but produces zero records.

    If I change the criteria to read:
    Like('%' + '75196' + '%')
    The query runs and produces over 750 records.

    Can somebody please tell me what is wrong.

    Many Thanks

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Enter the criteria in MSQuery as [Enter Agreement No] only and run it.

    Then in the spreadsheet, have a cell that has something like ="%"&UPPER(A2)&"%" where A2 is the place you enter you search criteria (i.e. 75196)

    Right click the table and select Parameters. Then choose "Get the value from the following cell" and enter the cell where you put the formula.

    You can also check the autorefresh checkbox if you want.

    Click ok and enter a new id in the "A2" cell..
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    01-15-2009
    Location
    Hertfordshire, England
    MS-Off Ver
    Excel 2007
    Posts
    9
    Thanks for the reply. Unfortunately I'm still getting zero records returned. The format of the field I am querying over looks something like:
    75196......001..00 (where the '.' are spaces)

    I notice that the 'Like' function is missing, should it be included somewhere?

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Sorry, yes, in your initial query enter: Like [Enter Agreement No]

    Then run the query to the spreadsheet and then continue on the above instructions...

  5. #5
    Registered User
    Join Date
    01-15-2009
    Location
    Hertfordshire, England
    MS-Off Ver
    Excel 2007
    Posts
    9
    I'm afraid it still doesn't work. It looks as though the query runs but doesn't return any data. I know there is data there as I can run the same type of query through crystal reports.

    Is there any other way of doing this?

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    I have queries myself that run using this method....so not sure why yours isn't working...

    maybe use formula: ="%"&A2&"%" instead.

  7. #7
    Registered User
    Join Date
    01-15-2009
    Location
    Hertfordshire, England
    MS-Off Ver
    Excel 2007
    Posts
    9
    Still not running. Could it be a connection problem between excel and msquery.
    I've attached a word doc showing screen shots of the properties and parameter windows (I thought this might help).
    Attached Files Attached Files
    Last edited by Smithsc; 01-16-2009 at 10:53 AM. Reason: forgot to attach file!

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Looks okay to me...

    so in 'GL Posting Data'!$B$2 you have the formula ="%"&A2&"%" where A2 is the actual cell you are entering the parameter in?

  9. #9
    Registered User
    Join Date
    01-15-2009
    Location
    Hertfordshire, England
    MS-Off Ver
    Excel 2007
    Posts
    9
    Yep. See attached doc...
    Attached Files Attached Files

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Well it looks like mine... so not sure what is going on.

    Run it the first time in MsQuery and send the results to Excel.. then retry entering a different number in A2...

  11. #11
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Another thing to check is Office Button, click Excel Options and in the Formulas section...you should have Automatic checked with Calculation Options

  12. #12
    Registered User
    Join Date
    01-15-2009
    Location
    Hertfordshire, England
    MS-Off Ver
    Excel 2007
    Posts
    9
    Still no luck. In the queries that work for you, do any of them extract data from a SQL server. Could there be an issue when using SQL data sources?

    Sorry for all these questions, it's just that if I can get this to work it would help a lot of people and save a lot of time.

  13. #13
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    I use an Oracle Server..... that could be it, although I don't see why...

    What if you replace the occurances of "%" in the formula with "*" ? Just as a guess...what happens? So ="*"&A2&"*"

  14. #14
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Look at Debra Dalgleish's response in this similar thread...

  15. #15
    Registered User
    Join Date
    01-15-2009
    Location
    Hertfordshire, England
    MS-Off Ver
    Excel 2007
    Posts
    9
    How do I find the thread?

  16. #16
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

  17. #17
    Registered User
    Join Date
    06-10-2010
    Location
    Leeds, England
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: MS Query - Wildcard 'Like' with a parameter

    Does anyone know a solution to this? I am trying to run a query and when I use a number I can do it fine, so it's '00'+[ASG] but when I try do it with a wildcard it's not working. I've tried

    Like [Store]+'%'

    Like('%'+[Store]+'%')

    and other variations, never works. If I replaced [Store] with 056 it works fine though

  18. #18
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: MS Query - Wildcard 'Like' with a parameter

    hi BenRoylance,

    This is quite an old thread. Can you please start your own thread as stated in the Rules?

    If you feel this old thread is particularly relevant you can include a link to it in your new thread.

    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  19. #19
    Registered User
    Join Date
    09-07-2012
    Location
    Roanoke, VA
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: MS Query - Wildcard 'Like' with a parameter

    In Excel 2010 MSQuery, the concatenation parameter in SELECT is two vertical bars - '||'. Would be the same in the WHERE clause. I got the wild card to work with this:

    WHERE (LIBRARY.FIELD like ('%'||?||'%'))

    This prompts the run-time variable box; or you can set the parameter value to reference a specific cell.

  20. #20
    Registered User
    Join Date
    01-28-2013
    Location
    Indianapolis
    MS-Off Ver
    Excel2007
    Posts
    1

    Re: MS Query - Wildcard 'Like' with a parameter

    Enter "%" (w/o quotes) into your parameter field as your wildcard indicator. The single % in a LIKE criteria parameter will run the field wide open.

  21. #21
    Registered User
    Join Date
    10-26-2011
    Location
    dfgdgs
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: MS Query - Wildcard 'Like' with a parameter

    GREAT

    like '%'||[Parámetro1]||'%'

    on EXCEL 2003 and ...

  22. #22
    Registered User
    Join Date
    10-26-2011
    Location
    dfgdgs
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: MS Query - Wildcard 'Like' with a parameter

    GREAT

    like '%'||[Parameter1]||'%'

    on EXCEL 2003 and ...
    SPAIN is good

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1