Sign in to follow this  
chbrules

[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 this post


Link to post
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 this post


Link to post
Share on other sites
Michalson    1657
Quote:
Original post by chbrules
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. =/


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 this post


Link to post
Share on other sites
smr    2468
Quote:
Original post by Michalson
Quote:
Original post by chbrules
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. =/


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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this