Solved

SQL / ADO Problem

Posted on 2000-03-20
6
150 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
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!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

759 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