By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,806 Members | 1,841 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,806 IT Pros & Developers. It's quick & easy.

Sorting four columns using sql query in query analyzer

P: 49
Hi to all

I have one table with 6 columns and 20 rows.I want to sort each and every column when i click the column name in the table.

for sorting i create one more page.when i click the column name it connect to sorting page and then page will be sorting. like this i wnat to write the code.
i wrote some code,but it not working properly.my code is

For first page:

<%userdetails=session("userdetails")
userpoint=instr(1,userdetails,",")
'mt=mid(userdetails,1,userpoint-1)
sort_var=request.querystring("valb4")

%>

<td bgcolor="black" nowrap><b><a href="hco_Qc_Status1_sort123.asp?valb4=#_id" ><b><font color="white" style="text-decoration:none">&nbsp;#</b></font></td>
<td bgcolor="black" nowrap><b><a href="hco_Qc_Status1_sort123.asp?valb4=id_id" ><b><font color="white" style="text-decoration:none">&nbsp;ID</b></font></td>
<td bgcolor="black" nowrap><b><a href="hco_Qc_Status1_sort123.asp?valb4=name" ><b><font color="white" style="text-decoration:none">&nbsp;Name</b></font></td>
<td bgcolor="black" nowrap><b><a href="hco_Qc_Status1_sort123.asp?valb4=team_name1" ><b><font color="white" style="text-decoration:none">&nbsp;Team</b></font></td>
<td bgcolor="black" nowrap><b><a href="hco_Qc_Status1_sort123.asp?valb4=Acc_no" ><b><font color="white" style="text-decoration:none">&nbsp;ACC</b></font></td>
<td bgcolor="black" nowrap><b><a href="hco_Qc_Status1_sort123.asp?valb4=job_no" ><b><font color="white" style="text-decoration:none">&nbsp;Job</b></font></td>
<td bgcolor="black" nowrap><b><a href="hco_Qc_Status1_sort123.asp?valb4=qc_id" ><b><font color="white" style="text-decoration:none">&nbsp;Status</b></font></td>
<td bgcolor="black" nowrap><b><a href="hco_Qc_Status1_sort123.asp?valb4=type_name" ><b><font color="white" style="text-decoration:none">&nbsp;Type</b></font></td>

<!--<td><b><font face="Verdana" size="2">&nbsp;Remarks</font></b></td>-->
<td bgcolor="black" nowrap><b><a href="hco_Qc_Status1_sort123.asp?valb4=error_name" ><b><font color="white" style="text-decoration:none">&nbsp;Error</b></font></td>

---

if sort_var="qc_id" then

''sqlqr="Select client_id,editor_id,qc_id,job_no,tc_time,qc_date,d ictator_name1,dictation_length,wt from tws_stats where qc_date='"&date&"'and job_no <> '' order by "& sort_var &" desc"
' sqlqr="Select id_id,team_name1,Acc_no,job_no,type_name,error_nam e,name from tws_stats where qc_date='"&date&"'and job_no <> '' order by "& sort_var &" desc"
sqlqr="select Id,name from tws_stats where qc_date='"&date&"' ORDER BY name DESC "
'sqlqr="Select name from tws_stats order by sort_var"
' Response.Write sqlqr

else
'sqlqr="Select client_id,editor_id,qc_id,job_no,tc_time,qc_date,d ictator_name1,dictation_length,wt from tws_stats where qc_date='"&date&"'and job_no <> '' order by "& sort_var &" asc"

'sqlqr="Select id_id,team_name1,Acc_no,job_no,type_name,error_nam e,name from tws_stats where qc_date='"&date&"'and job_no <> '' order by "& sort_var &" asc"
sqlqr="select Id,name from tws_stats where qc_date='"&date&"' ORDER BY name ASC "



And for sorting page code is :


%userdetails=session("userdetails")
userpoint=instr(1,userdetails,",")
'mt=mid(userdetails,1,userpoint-1)
sort_var=request.querystring("valb4")
%>

<td align="middle" bgcolor="black" nowrap><A href="Copy of Grades-Unacceptable.asp?valb4=#_id"><b><font color="white" style="TEXT-DECORATION: none">#</b></font></a></td>
<td align="middle" bgcolor="black" nowrap><font color="white"><A href="Copy of Grades-Unacceptable.asp?valb4=ID_id"><font color="white" style="TEXT-DECORATION: none"><b>ID</b></font></a></font></td>
<td align="middle" bgcolor="black" nowrap><font color="white"><A href="Copy of Grades-Unacceptable.asp?valb4=name"><font color="white" style="TEXT-DECORATION: none"><b>Name</b></font></a></font></td>
<td align="middle" bgcolor="black" nowrap><font color="white"><A href="Copy of Grades-Unacceptable.asp?valb4=team_name1"><b><font color="white" style="TEXT-DECORATION: none">Team</b></font></A></font></td>
<td align="middle" bgcolor="black" nowrap><font color="white"><A href="Copy of Grades-Unacceptable.asp?valb4=Acc_no"><font color="white" style="TEXT-DECORATION: none"><b>ACC</b></font></a></font></td>
<td align="middle" bgcolor="black" nowrap><font color="white"><A href="Copy of Grades-Unacceptable.asp?valb4=job_no"><font color="white" style="TEXT-DECORATION: none"><b>Job</b></font></a></font></td>
<td align="middle" bgcolor="black" nowrap><font color="white"><A href="Copy of Grades-Unacceptable.asp?valb4=qc_id"><font color="white" style="TEXT-DECORATION: none"><b>Status</b></font></a></font></td>
<td align="middle" bgcolor="black" nowrap><font color="white"><A href="Copy of Grades-Unacceptable.asp?valb4=type_name"><font color="white" style="TEXT-DECORATION: none"><b>Type</b></font></a></font></td>
<td align="middle" bgcolor="black" nowrap><font color="white"><A href="Copy of Grades-Unacceptable.asp?valb4=error_name"><font color="white" style="TEXT-DECORATION: none"><b>Error</b></font></a></font></td>


<%
if sort_var="qc_id" then
'sqlqr="Select client_id,editor_id,qc_id,job_no,tc_time,qc_date,d ictator_name1,dictation_length,wt from tws_stats where qc_date='"&date&"'and job_no <> '' order by "& sort_var &" desc"
' sqlqr="Select id_id,team_name1,Acc_no,job_no,type_name,error_nam e,name from tws_stats where qc_date='"&date&"'and job_no <> '' order by "& sort_var &" desc"
'ex table name = infos_today
sqlqr="select Id,name from infos_today where qc_date='"&date&"' ORDER BY name DESC "

'Response.Write sqlqr
else
'sqlqr="Select client_id,editor_id,qc_id,job_no,tc_time,qc_date,d ictator_name1,dictation_length,wt from tws_stats where qc_date='"&date&"'and job_no <> '' order by "& sort_var &" asc"
'sqlqr="Select id_id,team_name1,Acc_no,job_no,type_name,error_nam e,name from tws_stats where qc_date='"&date&"'and job_no <> '' order by "& sort_var &" asc"
sqlqr="select Id,name from infos_today where qc_date='"&date&"' ORDER BY name ASC "

'Response.Write sqlqr
end if
dim rs
'set rsIn =myconn.execute(sqlqr)
set rs=myconn.execute(sqlqr)
if not(rs.eof and rs.bof) then
get1=rs.getrows
set rs=nothing
get2=ubound(get1,2)
for i=0 to get2
%>



please check the above code.

please tell me the sql query for sorting 5 columns in a table.
Sep 1 '08 #1
Share this Question
Share on Google+
3 Replies


code green
Expert 100+
P: 1,726
please check the above code
No thanks. This looks like a VB problem not SQL server
Sep 1 '08 #2

P: 49
No thanks. This looks like a VB problem not SQL server
Hello sir,

Thanks for ur reply.Sir actually i want the sql query for sorting 5 columns in a table using query analyzer.If u know means please tell me.

thanks,
nagesh.
Sep 2 '08 #3

code green
Expert 100+
P: 1,726
i want the sql query for sorting 5 columns in a table using query analyzer.
Are you asking how to use the ORDER BY clause?
Expand|Select|Wrap|Line Numbers
  1. ORDER BY col1,col2,col3.....
Sep 2 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.