shanerobinson Posted August 20, 2008 Share Posted August 20, 2008 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 More sharing options...
aspnetguy Posted August 20, 2008 Share Posted August 20, 2008 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 More sharing options...
shanerobinson Posted August 20, 2008 Author Share Posted August 20, 2008 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 More sharing options...
justsomeguy Posted August 20, 2008 Share Posted August 20, 2008 If sortOrder is not a sort field then remove the comma between them. Link to comment Share on other sites More sharing options...
shanerobinson Posted August 21, 2008 Author Share Posted August 21, 2008 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 More sharing options...
justsomeguy Posted August 21, 2008 Share Posted August 21, 2008 Pass the sort order in the URL for the next page. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.