Solved

SQL / ADO Problem

Posted on 2000-03-20
6
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Industry Leaders: 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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

615 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