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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting/Record Count/duplicate elimination/Unique problem- Not an FAQ 2

Status
Not open for further replies.

Deadline

Programmer
Feb 28, 2001
367
US
Hello,

I have a page where I fetch and display the records for a complicated query. Let us consider, that it fetches colA, colB, and colC.

I am displaying it Table Format, with the provision to sort the records by colA, colB or colC. I mean, the user will click the heading of each column to sort; and when they do that, I simply pass the columnName as the sort key to the same page through QueryString.


In the page, I have a duplicate removal technique, where I am comparing colA of two adjacent rows like this :-
Code:
     WHILE NOT objRec.EOF
	IF  temp2 <> objRec.Fields(&quot;colA&quot;)  THEN       
           ....    
              /**Displaying the 
              recordset in table format**/
        END IF
	temp2 = objRec.Fields(&quot;colA&quot;)	 
	objRec.MoveNext	  
     WEND

At the end of table I am displaying the recordcount.

Here is where I face the problem ; for each time the user clicks on the heading of the column, the sort order varies and therefore the above loop returns different number of records for every sort made, because, the above loop will be logically correct only if the sorting is based on colA. For others, the loop, though works, is logically incorrect; I mean, as I said, it returns different number of rows each time.

Kindly help me to avoid this ugly situation and help me in displaying same number of records, whatever the sort key is.


Thank you...
RR

 
Please show your SQL String. The only thing that should be changing is the sort order (ORDER BY clause) not the names of the columns in the SQL String (which is kind of what I expect to see). Wushutwist
 
Wushutwist,

THank you..

You are right. Here is how I do it *partial*
Code:
SELECT CASE UCase(Request.QueryString(&quot;ORDER&quot;))
	CASE &quot;0&quot;
		strSQL = strSQL & &quot; ORDER BY colA,colB &quot; 
	CASE &quot;1&quot;
		strSQL = strSQL & &quot; ORDER BY colB,colA &quot; 
	CASE &quot;2&quot;
		strSQL = strSQL & &quot; ORDER BY colC,colA &quot;
	CASE ELSE
		strSQL = StrSQL & &quot; ORDER BY colA &quot;
END SELECT


And here is my partial table code :
Code:
Response.Write &quot;<th  align=center><A HREF=&quot; & Request.ServerVariables(&quot;SCRIPT_NAME&quot;)& &quot;?ORDER=0>COLUMN A</A></tH>&quot;
Response.Write &quot;<th  align=center><A HREF=&quot; & Request.ServerVariables(&quot;SCRIPT_NAME&quot;)& &quot;?ORDER=1>COLUMN B</A></tH>&quot;
Response.Write &quot;<th  align=center><A HREF=&quot; & Request.ServerVariables(&quot;SCRIPT_NAME&quot;)& &quot;?ORDER=2>COLUMN C</A></tH>&quot;

Thank you...
RR

 
Hello...
Can anyone help me in this ? Thank you...
RR

 
U could use to eliminate the repeated values
SELECT DISTINCT...
and please if u need help tell me more.... ________

George
 
Shaddow,
Thank you very much. I already am using DISTINCT. But consider a set of records like this:
Code:
colA    colB    colC
~~~~~~~~~~~~~~~~~~~~~
   1     XX      100
   2     XX      200
   2     YY      100

Here even using DISTINCT will get 3 records, agree ?

Now let us say I
Code:
ORDER BY colA
. Now when I use the loop as in first posting, I will fetch all the rows and display the rows, ONLY when two adjacent rows' colA value are not equal, I mean, in our example rows, I will be displaying the first two rows only. The third one will not be displayed. BUT the recordcount will always show 3 records.

I hope, I had expressed my problem correctly.. Can you help me out of this ?



Thank you...
RR

 
This records loks diffrent for me...
What you mean by diffrent... ________

George
 
I've found a sollution to your problem...
I see that your algorithm works just for colA
If u want to gneralize your algorithm use
the Fields property like this
objRec.Fields(&quot;fieldname&quot;) u just put objRec.Fields(filedindexposition)

if u have
select cola,colb,colc...

fileds(0) ->cola
fileds(1) ->colb
fileds(2) ->colc

And u could use your Request.QueryString(&quot;ORDER&quot;) variable to see what is the record u sorting for...
and u could use your code with few moddifications...

recposition=int(Request.QueryString(&quot;ORDER&quot;))
WHILE NOT objRec.EOF
IF temp2 <> objRec.Fields(recposition) THEN
....
/**Displaying the
recordset in table format**/
END IF
temp2 = objRec.Fields(recposition)
objRec.MoveNext
WEND

hope this helps you...
Iu have more questions please ask... ________

George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top