I would like to order by my results on a search page for the initial search and the search within search. I am having syntax issues and was hoping someone could point me in the right direction,

Here's the full code. What I have tried will be below the code.

Code:
<%
u_search=request.form("u_search")
u_search = Replace(u_search, "'", "")
u_prev_search=request.form("u_prev_search")
u_search_within=request.form("u_search_within")
' check to see if the user has inputted anything to search
if u_search <> "" then
'if the user inputted a search and it is the first search
'make prev_search equal to the current search 
if u_prev_search = "" then 
u_prev_search=u_search
else
'if the user entered a search prior add it to the prev_search
u_prev_search=u_prev_search &","& u_search
'if there are previous searches split up the u_search field into arrays
g_prev_search=split(u_prev_search,",")
num_inputted=ubound(g_prev_search)
end if
sql= "select * from issues where (Ticket & TicType & issrepuser & equipment & location & trouble1 & status & odate & File1Name & File1Size & File2Name & File2Size & File3Name & File3Size & udate & Group1I & Group2I like '%%"& u_search & "%%') "

'Checks to see if the user requested to search within the results of a
'previous search by appending the previous search to the sql
'of the new search
if u_search_within = "Yes" then
for counter =0 to num_inputted-1
sql=sql& "and (Ticket & TicType & issrepuser & equipment & location & trouble1 & status & odate & File1Name & File1Size & File2Name & File2Size & File3Name & File3Size & udate & Group1I & Group2I like '%%"& g_prev_search(counter) & "%%') "
next
end if ' end the search within a search
accessdb =("repairs.mdb")
cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, cn 
'if there are no records found display no records found
if rs.eof then
%>
No tickets were found 
<%' if records are found display them
else 
rs.movefirst
do while Not rs.eof
%>

<%
linecheck=rs("TicType")

%>

<%
if linecheck = "new" then %>
<table width="100%"><tr><td><hr class="long"><hr class="long"></td></tr></table>

<% else %>
<table width="100%"><tr><td><hr class="long2"></td></tr></table>
<% end if
%>


<div align="left">
<table width="100%">
<tr>
<td width="15%">
Ticket: <%= rs("Ticket") %> </td>
<td width="15%"> 
Submitted by: <%= rs("issrepuser") %></td>
<td width="15%"> 
Submitted: <%= rs("Odate") %></td>
<td width="15%"> 
Last Updated: <%= rs("udate") %></td>
<td width="15%">
Type: <%= rs("TicType") %></td>
<td width="15%">
Status: <%= rs("status") %>
</td></tr></table>


<table width="100%"><tr><td>
<b>Equipment: </b>
<%= rs("equipment") %>
</td></tr></table>
<table width="100%"><tr><td>
<b>Location: </b>
<%= rs("location") %>
</td></tr></table>
<table width="100%"><tr><td>
<b>Trouble: </b>
<%= rs("trouble1") %></td></tr></table>
<table width="100%"><tr><td>
<b>Files (size): </b>
<%response.write("<a href=""upload2/" & rs("File1Name") & """ target=""_blank"">" & rs("File1Name") & "</a>")%>&nbsp;<%= rs("File1Size") %>&nbsp;&nbsp;&nbsp;<%response.write("<a href=""upload2/" & rs("File2Name") & """ target=""_blank"">" & rs("File2Name") & "</a>")%>&nbsp;<%= rs("File2Size") %>&nbsp;&nbsp;&nbsp;<%response.write("<a href=""upload2/" & rs("File3Name") & """ target=""_blank"">" & rs("File3Name") & "</a>")%>&nbsp;<%= rs("File3Size") %>&nbsp;
</td></tr></table></div>




<%
rs.movenext
loop
end if  ' end of check for records  
end if ' end the check for a user inputted value
%>
</div>

<br>
<br>
<!-- Begin Form Input Area -->

<form action="<%= request.servervariables("script_name") %>" method="post">

<br><br><p class="center2">
<input type="text" name="u_search" value="<%= u_search %>">
<br><br>

<% if u_search <> "" then %>
<input type = "radio" name="u_search_within" checked value="No"> Search &nbsp; 
<input type = "radio" name="u_search_within" value="Yes"> Search within results
<% if u_search_within = "Yes" then %>
<input type = "hidden" name="u_prev_search" value="<%= u_prev_search %>">
<% else %>
<input type = "hidden" name="u_prev_search" value="<%= u_search %>">
<% end if %>
<br>
<% end if %>

<input type="submit" value="Search">
</p></form>
<!-- End Form Input Area -->


What I have tried with no luck:


This sorts on the initial search but throws the error below on the search within


sql= "select * from issues where (Ticket & TicType & issrepuser & equipment & location & trouble1 & status & odate & File1Name & File1Size & File2Name & File2Size & File3Name & File3Size & udate & Group1I & Group2I like '%%"& u_search & "%%') order by Ticket desc, TicType='new', ID asc "

sql=sql& "and (Ticket & TicType & issrepuser & equipment & location & trouble1 & status & odate & File1Name & File1Size & File2Name & File2Size & File3Name & File3Size & udate & Group1I & Group2I like '%%"& g_prev_search(counter) & "%%') "



Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error in ORDER BY clause.



-----------------------------------------------

This sorts on the initial search but throws the error below on the search within ( has the ; at the end )


sql= "select * from issues where (Ticket & TicType & issrepuser & equipment & location & trouble1 & status & odate & File1Name & File1Size & File2Name & File2Size & File3Name & File3Size & udate & Group1I & Group2I like '%%"& u_search & "%%') order by Ticket desc, TicType='new', ID asc; "

sql=sql& "and (Ticket & TicType & issrepuser & equipment & location & trouble1 & status & odate & File1Name & File1Size & File2Name & File2Size & File3Name & File3Size & udate & Group1I & Group2I like '%%"& g_prev_search(counter) & "%%') "



Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Characters found after end of SQL statement.




-----------------------------------------------



This produces no errors and sorts correctly on the search within but does not sort on initial search

sql= "select * from issues where (Ticket & TicType & issrepuser & equipment & location & trouble1 & status & odate & File1Name & File1Size & File2Name & File2Size & File3Name & File3Size & udate & Group1I & Group2I like '%%"& u_search & "%%') "


sql=sql& "and (Ticket & TicType & issrepuser & equipment & location & trouble1 & status & odate & File1Name & File1Size & File2Name & File2Size & File3Name & File3Size & udate & Group1I & Group2I like '%%"& g_prev_search(counter) & "%%') order by Ticket desc, TicType='new', ID asc;"




Thanks for any thoughts!

Mark