0

My website sells garden plants so there are a lot of apostrophes in the names, i.e Canna 'Taney'. When I list the plants in a certain category, or return search results, those with an apostrophe get listed at the top and those without at the bottom, like this :

Canna 'Aphrodite'

Canna 'Brilliant'

Canna 'Carnival'

Canna 'Cleopatra'

Canna 'En Avant'

Canna Australia

Canna Bird of Paradise

Ideally Canna Australia should be second in the list and Canna Bird of Paradise third. I assume getting the the "order by" to ignore the apostrophes is the answer, can it be done?

set rscatlist=db.execute("select * from products where catcode=" & catcode & " order by name ASC")

Is the code that needs modification.

2

1 Answer 1

2

You can remove any apostrophe in "order by" condition:

select * from products where catcode=" & catcode & " order by REPLACE(name,'\'','') ASC 
Sign up to request clarification or add additional context in comments.

3 Comments

Would have preferred you had at least pointed out how open to SQL Injection writing SQL in Classic ASP like this is. Where does catcode come from, if it's pasted by a form or through the URL then the OP needs to consider re-writing this using ADODB.Command.
REPLACE(name,'\'','') sorted it out and I'm grateful for that answer. @Lankymart, I know nothing about SQL injection but if there is a better way to resolve this I'd like to be pointed in the right direction. catcode is being passed via the URL.
@MalcolmBrowne If you know nothing about SQL Injection and are building web content suggest you learn fast. It is where using crafted exploits on the URL querystring inputs added directly into SQL queries can open up more access to the database then you first anticipated, from changing content to completely deleting it. Take a look at the linked question to learn more. Also good explanation of what SQL Injection is here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.