Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting

Status
Not open for further replies.

YodaMan81

Technical User
Jul 8, 2003
94
0
0
US
I have an ASP page that pulls info from our database thru MS SQL.
As it is out putted from SQL it is sorted alphabetically. I need to give the user the ability to sort by date if they so desire.
Can someone plese direct me to a website that might teach me how to do that?

-Thanks
 
I would say the easy way to do this is to have a option prior to the query run. Then ORDER BY in the SQL execute by either the alpha or by the date on the users choice



___________________________________________________________________
[sub]
The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page
[/sub]
 
[;-)] have a closer look at this formum list under "THREAD ORDER".
You start your page with a default order and present the user links to alternatives. Each link starts the page, but with a order-variable.

Roughly:

mypage.asp:
Code:
<%
dim cOrder
cOrder = request.querystring("order")

' build SQL
cSQL = "SELECT * FROM TT "
if cOrder = "1" then
 cSQL = cSQL & "ORDER BY Field1"
elseif  cOrder = "2" then
 cSQL = cSQL & "ORDER BY Field2"
else
 ' make this the default sort order(!)
 cSQL = cSQL & "ORDER BY Field3"
end if
%>



<a href="mypage.asp?order=1">Field1</a>
<a href="mypage.asp?order=2">Field2</a>
<a href="mypage.asp?order=3">Field3</a>

ttmug.gif
 
Not really sure what you mean by "THREAD ORDER"

I am not so familiar with SQL either. I would know how to put the order by command in there, but not how to access the information differently depending on what the user chooses.

 
you can change the order of the threads in a tek-tips forum...

ttmug.gif
 
well yea its great that i can do the sort within this forum...but it does nothing for me to look at it. Need to know how to do it.
Any other ideas?

Also I know this is not a SQL forum but I was wondering when I do a request.querystring on my asp page, can I sort by a field at that point?

Currently this is what I use to retrieve info:

rs.source = rs.source & ",@AcctNo='" & request.form("actno") & "'"

Can I change this to something like:

rs.source = rs.source & ",@AcctNo='" & request.form("actno") & "ORDER BY Field1" & "'"


-Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top