Solved

SQL / ADO Problem

Posted on 2000-03-20
6
144 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Print Graphic and Text to Epson TM-T88v 12 114
Working with hours 3 31
How to debug this code 7 50
Adding to a VBA? 6 48
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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now