Jump to content

sql structure issues


shanerobinson
 Share

Recommended Posts

Hi everyone,I'm pretty new to SQL as you will probably be able to tell. i'm trying to construct and sql string which will provide the users with a way of selecting a sort order from a form and when they have selected this order and navigate through the records displayed, i want the sort order to remain.My plan is to use query strings to remember the sort order selected and alter the sql accordingly. this is my Sql attempt which come up with the error of expected end."SELECT * FROM dbo.products WHERE category_name='lcd tv' OR category_name='televisions' OR category_name='plasma tv' ORDER BY" & Request.QueryString("SortField") & Request.QueryString("SortOrder")"'"Any suggestions and help would be very appreciated,Thank you..

Link to comment
Share on other sites

try this

"SELECT * FROM dbo.products WHERE category_name='lcd tv' OR category_name='televisions' OR category_name='plasma tv' ORDER BY " & Request.QueryString("SortField") & ", " & Request.QueryString("SortOrder")

This is assumeing SortField and SortOrder are not supposed to be concatenated and are 2 different sort params.

Link to comment
Share on other sites

try this
"SELECT * FROM dbo.products WHERE category_name='lcd tv' OR category_name='televisions' OR category_name='plasma tv' ORDER BY " & Request.QueryString("SortField") & ", " & Request.QueryString("SortOrder")

This is assumeing SortField and SortOrder are not supposed to be concatenated and are 2 different sort params.

I tried the code and i get the following error:Microsoft OLE DB Provider for SQL Server error '80040e14'Incorrect syntax near ','.SortField is the field name to be sorted by...SortOrder is an option of ASC or DESC
Link to comment
Share on other sites

Thankyou for your reply, i was still getting error but i have now re-written the code as below,"SELECT * FROM dbo.products WHERE category_name='lcd tv' OR category_name='televisions' OR category_name='plasma tv'" & Request.Form("SortField")<form action="delete2.asp" method="post"> Sort by: <select name="SortField"> <option>ORDER BY display_price ASC</option> <option>ORDER BY display_price DESC</option> </select> <input type="submit" name="SortButton" value="Select"></form>The problem im having now is that im limiting the number of records being displayed on a page and when i click to go to the next 10 records the sort order is not being passed..Any ideas how i can get round this?Thank you.

Link to comment
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
 Share

×
×
  • Create New...