Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building SQL Statement with Like Clause

Status
Not open for further replies.

jtrembla

ISP
Jul 6, 2006
104
US
Code:
 strSQL = "SELECT ULTIMATE_DUNS FROM T_DB_MATCH" _
            & " WHERE (SPONS_DFE_NAME) Like '" & strCompany & "*'" _
            & " GROUP BY ULTIMATE_DUNS"

the code above returns 0 records. However, if I debug.print strSQL and paste the output into the query window I get results. Is the problem with the Like function?
 
Total guess, here, because your concatenation and syntax look correct - but maybe try adding the asterisk to the string variable before concatenating it in your SQL string? i.e.:
Code:
strCompany = strCompany & "*"

strSQL = "SELECT ULTIMATE_DUNS FROM T_DB_MATCH" _
            & " WHERE (SPONS_DFE_NAME) Like '" & strCompany & "'" _
            & " GROUP BY ULTIMATE_DUNS"
HTH,

Ken S.
 
How are you executing the query?

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
the code above returns 0 records
the code above simply set a variable value and thus I don't understand why you're expecting some records to be returned ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top