Solved

SQL / ADO Problem

Posted on 2000-03-20
6
149 Views
Last Modified: 2013-11-23
Hi

I am using vb5 /ADO2.1 with SQL Server 7 and opening a recordset with the following statement:

rs.open "SELECT surname FROM patient WHERE surname LIKE 'O''%'
ORDER BY surname",aDB, adOpenForwardOnly, adLockReadOnly

When I list the results the names are in the following order:

O' Brien
O Donnell
O' Donnell
O' Grady
Oakes
Oakey
O'Brien

How do I only list the names with a ' in them. It appears to be ignoring the ' when sorting.

Thanks
0
Comment
Question by:sbmc
6 Comments
 
LVL 2

Accepted Solution

by:
p_biggelaar earned 100 total points
ID: 2639538
Instead of WHERE surname LIKE 'O''%' which also returns the other names, you could ask more specifically for WHERE LEFT(surname, 2)='O'''. Hope this is what you need.
0
 
LVL 1

Expert Comment

by:Kurvy
ID: 2639634
Amend your sql statement so that the like wild card search treats the ' as a character instead of a special character
ie
rs.open "SELECT surname FROM patient WHERE surname LIKE 'O''%' amend it to
rs.open "SELECT surname FROM patient WHERE surname LIKE "O%'%"

This should give you only the names taht start O'whatever

0
 
LVL 2

Expert Comment

by:damienm
ID: 2639680
Use:

rs.open "SELECT surname FROM patient WHERE surname LIKE " & """" & "O'% " & """" & "ORDER BY surname",aDB, adOpenForwardOnly, adLockReadOnly
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:damienm
ID: 2639685
That should be:

rs.open "SELECT surname FROM patient WHERE surname LIKE " & """" & "O'%" & """" & " ORDER BY surname",aDB, adOpenForwardOnly, adLockReadOnly
0
 
LVL 2

Author Comment

by:sbmc
ID: 2642876
damienm

Couldnt get this to work at all. Thanks anyway.


p_biggelaar

Thanks. Your solution worked. If you care to resubmit as answer you get the points.

sbmc
0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2643781
Guess I don't need to resubmit?!

Glad to be of help...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question