Home > ASP Development > display duplicates record..

display duplicates record..



hi..i m selecting company by datewise and displaying it..

but problem is for some date..it print exactly duplicate of existing records..means each company it print twice..

below is my code..


asp Code:
















Original
- asp Code


  1.  
  2.  
  3. <%
  4. if trim(Request.Form("sday")) = "" then
  5. from_date = trim(Request.QueryString("from_date"))
  6. end if
  7. to_date =emonth&"/"&eday&"/"&eyear
  8. to_date = to_date
  9.  
  10. if trim(Request.Form("eday")) = "" then
  11. to_date = trim(Request.QueryString("to_date"))
  12. end if
  13.  
  14. [COLOR=DarkRed]oRecComp.Open "Select company_master.company_id, company_master.company_name, company_master.record_date, company_master.approved from company_master, company_branch where (company_master.company_id=company_branch.company_  id) and (company_master.record_date between '"& from_date &"' and '"& to_date &"') and (company_master.approved is null or company_master.approved = 0) order by company_master.record_date, company_master.company_name ",oConn,adOpenKeyset[/COLOR]
  15.     %>
  16.     
  17.     
  18.  <body>
  19.  
  20.  
  21. <table width="80%" border="0" cellpadding="3" align="center" class="bdlinks">
  22. <form name="f1"   action="comp_alpha5.asp"  method="post" >
  23. <tr><td><a href="#" onClick="dubey(true)">Checked All</a>&nbsp;&nbsp;&nbsp;<a href="#" onClick="dubey(false)">Unchecked All</a></td></tr>
  24.    <tr bgcolor="#E4E4E4" class="N">
  25.     <td align="left" width="10%">
  26.    <%
  27.    
  28.  
  29.     while not oRecComp.EOF
  30.     for i = 1 to oReccomp.recordcount
  31.     response.write "<tr><td bgcolor=""#E4E4E4"" width=""100%"" ><input type=""checkbox"" name=""c1"" value=" & oRecComp("Company_id")& " ><font size=""1"">" & oRecComp("Company_name") & "</font></td><td bgcolor=""#E4E4E4""  >"&i&"</td></tr>"
  32.    
  33.     oRecComp.MoveNext
  34.     next
  35.     wend
  36.    
  37. oReccomp.close
  38. set oReccomp=nothing
  39. oConn.close
  40. set oConn=nothing
  41.    
  42.    
  43.   %>



    
Guest


Hi,



i think this section


Code:



while not oRecComp.EOF
for i = 1 to oReccomp.recordcount
response.write "<tr><td bgcolor=""#E4E4E4"" width=""100%"" ><input type=""checkbox"" name=""c1"" value=" & oRecComp("Company_id")& " ><font size=""1"">" & oRecComp("Company_name") & "</font></td><td bgcolor=""#E4E4E4"" >"&i&"</td></tr>"
oRecComp.MoveNext
next
wend




should be something like this


Code:



i = 1
while not oRecComp.EOF
response.write "<tr><td bgcolor=""#E4E4E4"" width=""100%"" ><input type=""checkbox"" name=""c1"" value=" & oRecComp("Company_id")& " ><font size=""1"">" & oRecComp("Company_name") & "</font></td><td bgcolor=""#E4E4E4"" >"&i&"</td></tr>"
oRecComp.MoveNext
i = i + 1
wend




hope this helps

Was this answer helpful ? Yes No   
Guest


You got two loops while and for that is why the duplication


Code:



while not oRecComp.EOF
for i = 1 to oReccomp.recordcount
response.write "<tr><td bgcolor=""#E4E4E4"" width=""100%"" ><input type=""checkbox"" name=""c1"" value=" & oRecComp("Company_id")& " ><font size=""1"">" & oRecComp("Company_name") & "</font></td><td bgcolor=""#E4E4E4"" >"&i&"</td></tr>"
oRecComp.MoveNext
next
wend




change the above to


Code:



If not oRecComp.EOF then
for i = 1 to oReccomp.recordcount
response.write "<tr><td bgcolor=""#E4E4E4"" width=""100%"" ><input type=""checkbox"" name=""c1"" value=" & oRecComp("Company_id")& " ><font size=""1"">" & oRecComp("Company_name") & "</font></td><td bgcolor=""#E4E4E4"" >"&i&"</td></tr>"
oRecComp.MoveNext
next
end if



Was this answer helpful ? Yes No   
Guest


ok i will try little latter both code.......and post result.......thanx both Jako & Barney

Was this answer helpful ? Yes No   
Guest


no problem, let us know if it works

Was this answer helpful ? Yes No   
Guest


HI.. still it showing duplicates.......i checked my both table company_master and company_branch......in company_master i have unique records...but in company_branch i have two records for a record in company_master...i think this is the reason for displaying duplicates......so can we write such a query which give my desire result........

thanx

Was this answer helpful ? Yes No   
Guest


hi,

try adding a group by clause


Code:




"Select company_master.company_id, company_master.company_name,
company_master.record_date, company_master.approved
from company_master, company_branch
where (company_master.company_id=company_branch.company_ id)
and (company_master.record_date between '"& from_date &"' and '"& to_date &"')
and (company_master.approved is null or company_master.approved = 0)

group by company_master.company_id, company_master.company_name,
company_master.record_date, company_master.approved

order by company_master.record_date, company_master.company_name "




hope this helos

Was this answer helpful ? Yes No   
Guest


tanx jako...........its perfect...if u r there always oneday i will become master in database.........

Was this answer helpful ? Yes No   
Guest


no worries, glad I could help

Thanx for the nice words

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved