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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql-access using Like Clause

Status
Not open for further replies.

shuklix

Programmer
Jul 15, 2003
21
0
0
AU

Hi All,

I am trying to use a like clause to search for records from Access Db. How the query does not return any rows.

When I run the same exact query directly in access it works perfectly.


Code:
Dim selectSQL 
getConnection() ' gets the connection
Set recordSet = Server.CreateObject("ADODB.Recordset")
selectSQL = "SELECT * FROM Members WHERE "
selectSql = selectSql &  " Members.Userid LIKE '*sa*' " 

/* 	
'selectSql = " select * from Members" 
 If I use this above statement , the query returns all the results.
*/

Response.Write(selectSql) 
'Prints select * from Members where useriD like '*sa*'
' When run in access the query returns rows ,
' when I run it here, it does not return any thing.
' I have also tried, replacing single quotes with
'  double without luck. select * from Members where useriD like "*sa*"

set recordSet = oConn.Execute(selectSql)

if (NOT recordSet.EOF) then
  Response.Write(&quot;<br> Record Set is NOT EMPTY <br>&quot;) 
else
  Response.Write(&quot;<br> Record Set is EMPTY <br>&quot;) 
end if


TIA,
Saurabh
 
Found the solution.

I should have used '%sa%' instead of '*sa*'

Thanks,
Saurabh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top