# [ASP] Query problems

## Recommended Posts

chbrules    170
I'm trying to run this query to my database, but the ORDER BY never seems to work, it's not arranging the record set the way I want (desc/asc). Can anyone tell me why? I've checked the values of order_by and order and they're the right ones. This is really screwy. =/
query = "SELECT [id],[ProductNum],[PartName],[Flag] FROM products WHERE ProductNum LIKE '%" & search & "%' ORDER BY '" & order_by & "' " & order

##### Share on other sites
ApochPiQ    23064
What are the actual values of order_by and order? What happens if you replace them with explicit values directly in the query? How are the records being arranged, and how is that different from the result you are trying to achieve?

##### Share on other sites
chbrules    170
I finally found out the problem. Don't use single quotes for the column name in the ORDER BY. I hate ASP if not SQL. =/

##### Share on other sites
Michalson    1657
Quote:
 Original post by chbrulesI finally found out the problem. Don't use single quotes for the column name in the ORDER BY. I hate ASP if not SQL. =/

It's neither ASP or SQLs fault. You where sorting by a literal constant (a string) instead of by a column. Don't blame a language because you don't understand the basics.

##### Share on other sites
smr    2468
Quote:
Original post by Michalson
Quote:
 Original post by chbrulesI finally found out the problem. Don't use single quotes for the column name in the ORDER BY. I hate ASP if not SQL. =/

It's neither ASP or SQLs fault. You where sorting by a literal constant (a string) instead of by a column. Don't blame a language because you don't understand the basics.

Seconded.

I was writing the exact same thing before I noticed you had posted it.

##### Share on other sites
chbrules    170
I meant I hate the syntax of it all. Working between like 10 languages (web and programming), I jumble things up sometimes. I had just been stuck on that for a while until I ran a query through my enterprise manager and fiddled w/ the syntax.

##### Share on other sites
_jinx_    139
just out of curiosity what database you running?