473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

SQL LIKE statements

Hai, i'm new here, i would like to ask about SQL statements, i'm using VB6.0 and my systems if more on searching record, so the SQL statements is very important to search a record, so back to the question, i do this to search the "company name"
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdNameView_Click()
  2. Dim strSQL As String
  3. inputName = UCase(txtName.Text)
  4.     Set rs = New ADODB.Recordset
  5.     If inputName <> "" Then
  6.         strSQL = "SELECT * FROM SUPPLIER WHERE sName LIKE '*" & inputName & "*'"
  7.         MsgBox strSQL
  8.         rs.Open strSQL, conn, adOpenKeyset, adLockPessimistic, adCmdText
  9.         fillfields
  10.     End If
  11.  
  12. End Sub
And here the method of fillfields()
Expand|Select|Wrap|Line Numbers
  1. Public Sub fillfields()
  2.  
  3.                 NotEditable
  4.                 frameSDetail.Visible = True
  5.                 If Not (rs.BOF = True Or rs.EOF = True) Then
  6.                     txtsName.Text = rs.Fields("sName")
  7.                     txtsAddress.Text = rs!sAddress
  8.                     txtPost_Code.Text = rs!Post_Code
  9.                     txtCity.Text = rs!City
  10.                     txtPhone.Text = rs!Phone
  11.                     txtEmail.Text = rs!Email
  12.                     txtFax.Text = rs!Fax
  13.                     txtService.Text = rs!Service
  14.                 Else
  15.                     MsgBox "No Record Match", vbExclamation, "Cannot Move"
  16.                 End If
  17.                 Exit Sub
  18.  
  19. End Sub
I got the msg "No Record Match" when i try the LIKE statements in the Microsoft Office access same as my code above, it return correct output. then i thought it is because of the logic error in fillfields method, then i try change the LIKE statements to
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM SUPPLIER WHERE sName = '" & inputName & "'
it return a correct output. For your information sName field cannot be the same and i already create a code to validate it. Can anyone can help me to trace the logic error on it?

thanks in advance
Aug 15 '08 #1
6 7075
jeffstl
432 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM SUPPLIER WHERE sName LIKE '% & inputName & %'"
  2.  
  3.  
SQL syntax for LIKE uses % in most cases. Not *
Aug 15 '08 #2
I have always used astrik's but I don't think that is the problem. I would change adLockPessimistic to adLockOptimistic.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdNameView_Click()
  2. Dim strSQL As String
  3. inputName = UCase(txtName.Text)
  4.     Set rs = New ADODB.Recordset
  5.     If inputName <> "" Then
  6.         strSQL = "SELECT * FROM SUPPLIER WHERE sName LIKE '*" & inputName & "*'"
  7.         MsgBox strSQL
  8.         rs.Open strSQL, conn, adOpenKeyset, adLockOptimistic, adCmdText
  9.         fillfields
  10.     End If
  11.  
  12. End Sub
Let me know if that doesn't work.

Edward
Aug 15 '08 #3
jeffstl
432 Expert 256MB
I have always used astrik's but I don't think that is the problem. I would change adLockPessimistic to adLockOptimistic.

Edward
* Isn't a universal syntax for SQL like.

% as far as I know..is more universal across multiple database platforms.

Why not to use * in SQL Like

I also do not think the problem is the locking method of opening the recordset.

That only relates to the contraints on the records of your database in terms of updating and inserting.

It has nothing to do with whether or not records will be returned in a SELECT.
Aug 16 '08 #4
* Isn't a universal syntax for SQL like.

% as far as I know..is more universal across multiple database platforms.

Why not to use * in SQL Like

I also do not think the problem is the locking method of opening the recordset.

That only relates to the contraints on the records of your database in terms of updating and inserting.

It has nothing to do with whether or not records will be returned in a SELECT.
Yes!! It works!, thank u everyone, my problem solved, must use the "%" symbol to make it works

Expand|Select|Wrap|Line Numbers
  1.  strSQL = "SELECT * FROM SUPPLIER WHERE sName LIKE '%" & inputName & "%'"
Aug 19 '08 #5
I think my problem solve, today, my Access 2003 and VB6.0 act weird. Here what i face today:

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM SUPPLIER WHERE sName LIKE '%" & inputByName & "%'"
i enter word "AM" and my VB return correct result.

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM SUPPLIER WHERE City LIKE '%" & inputByName & "%'"
i enter word "W" my program say Cannot find Record

i feel weird, then i try in Microsoft office 2003
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM SUPPLIER WHERE sName LIKE '%AM%'
Microsoft office return no record found

then i try in Microsoft office 2003
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM SUPPLIER WHERE sName LIKE '*AM*'
Microsoft office return correct result

then i try in VB6.0
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM SUPPLIER WHERE sName LIKE '*AM*'
VB6.0 return cannot find record

Can anyone explain to me what happen
Aug 21 '08 #6
QVeen72
1,445 Expert 1GB
Hi,

For VB6 + ADO + Access Combination, you need to query with %:

SELECT * FROM SUPPLIER WHERE sName LIKE '%AM%'

Regards
Veena
Aug 23 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Bart Nessux | last post by:
Should an if statement have a corresponding else statement? Or, is it OK to have an if statement by itself. For completeness, it seems the two should be together, but from experience I know that a...
9
by: Jaime Wyant | last post by:
I know I've seen this somewhere, but can't seem to google it. Is there a way to use an alternate statement separator, other than the default ';'? jw
1
by: Tom D | last post by:
I'm rewriting a database interface that our company currently has. Currently it's using the Pear::DB interface, but we found that that was introducing a bit too much overhead. I'm rewriting the...
39
by: slogging_away | last post by:
Hi - I'm running Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32, and have a script that makes numerous checks on text files, (configuration files), so discrepancies can be reported. The script...
0
by: Fuzzyman | last post by:
Hello all, The following is a copy of a blog entry. It's asking a question about future statements and the built in compile function. I'd appreciate any pointers or comments about possible...
20
by: Neroku | last post by:
Hello, i would like to know what the serious definition of statements and expressions is: i know an expression are evaluated to a value, i.e: 1 == 2 5+7 foo( 1,2) and a statement is...
2
by: ojorus | last post by:
Hi! Some questions regarding the mysqli-extension (php5) 1) Prepared statements: If I understand things right, prepared statements will give better performance if you make several similar...
3
by: Dmitri | last post by:
Hello! I have a developer that is playing around with some SQL statements using VB.NET. He has a test table in a SQL 2000 database, and he has about 2000 generated INSERT statements. When the...
0
by: Gary Herron | last post by:
Ohad Frand wrote: There is no way you can consider 'elif', 'else', 'except', and 'from' statements. However, as someone pointed out, the kwlist from the keyword module is the closest thing we...
0
by: Ohad Frand | last post by:
Hi Thanks a lot for your reply I think the main uses for it is to study the language and to see that I didn't miss anything else or that something is changed from one version to another. The...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.