SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member
    Join Date
    Jul 2008
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    asp sort column questions

    I created 2 ASP pages. One page, search.asp to search betweek 2 dates (Start and End).

    and this page, results.asp is to display data.

    It works fine for the search results. When I used the sort code in, it returns errors and never worked.



    80040e14|Incorrect_syntax_near_the_keyword_'Where



    can anyone please take a look to see what I did wrong?



    Thanks very much!



    Code:
    <%
    
                Sort = Request.QueryString("Sort")
    
                SortBy = Request.QueryString("SortBy")
    
                            SELECT CASE Sort
    
                                        CASE "asc"
    
                                                    Sort = "desc"
    
                                        CASE "desc"
    
                                                    Sort = "asc"
    
                                        CASE "else"
    
                                                    Sort = "asc"
    
                            END SELECT
    
     
    
    Set Conn = Server.CreateObject("ADODB.Connection")
    
    Conn.open strConn
    
     
    
                sqlStr = "Select ID, Dept, Start, End From qry_students "
    
                                        if len(SortBy) > 0 then _
    
                                        sqlStr = sqlStr & " order by " & SortBy & " " & Sort
    
                                        sqlStr = sqlStr & " Where "
    
                strWhere = ""
    
                strBetween = "BETWEEN"
    
     
    
    strStart = Request("Start")
    
    strEnd = Request("End")
    
    If IsDate(strStart) And IsDate(strEnd) Then
    
                strWhere = strWhere & "(Start >= '" & strStart & "' AND End <= '" & strEnd & "') "
    
    End If
    
     
    
                Set oRs = Server.CreateObject("ADODB.Recordset")
    
                oRs.Open sqlStr, Conn
    
    %>
    
     
    
     
    
    <html>
    
    <head>
    
    <title>Search Results</title>
    
    </head>
    
     
    
    <body bgcolor="#FFFFFF">
    
     
    
    <table>
    
                <tr>
    
                            <td><a href="results.asp?ID=<%=Request("ID")%>&Start>=strStart&End<=strEnd&SortBy=Dept&Sort=<%=Sort%>" title="Sort by Dept">Dept</a></td>
    
                            <td>Start</td>
    
            <td>End</td>
    
                </tr>
    
    </table>
    
    </body>
    
    </html>

  2. #2
    SitePoint Zealot gidday's Avatar
    Join Date
    Jan 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi jennypretty

    Here's a clue. Check out this bit of your url.

    Start>=strStart&End<=strEnd
    Joe
    "All that is necessary for the triumph of evil
    is that good men do nothing."

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,214
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    the WHERE clause must come before the ORDER BY clause, not after it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •