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

how can i build this query

Status
Not open for further replies.

andypower

Programmer
Aug 10, 2004
23
0
0
IN
my self avinash
i m developing one application in vb 6 and sql server 7
i have one table name - Salesvoucher which has fields like voucherno,voucherdate,debitto,creditto,amount.
i want to show all my voucher records in ascending order by date.
when i display it i used some button to navigate list so that user get some friendly interface these buttons r MoveFirst,Movenext,MovePrevious,MoveLast. i write query for each button which display TOP 20 records order by voucherno when i click to NExt Button it display next TOP 20 record so on....but now i want to display the record by using grouping on date. i.e say i have 10 records of voucherdate 01/05/2004, 15 records of voucherdate 8/6/04 and 4 records of voucherdate 15/6/04. then i want to display these records by group on voucherdate i.e when i click to MoveFirst Button then all records of date 01/05/2004 should display then i click to Next Button then all records will come of 8/6/04 date like this.
so plz help me in building these query
 
SELECT COUNT(*) AS Count, voucherdate
FROM Salesvoucher
GROUP BY voucherdate
 
A more detailed solution:

First, create a recordset with distinct values for each voucherdate:

Code:
rsDates.Open "SELECT DISTINCT voucherdate FROM Salesvoucher ORDER BY voucherdate", ConnectionObject

Then, use these unique voucher dates to retrieve and display records that have that same date:

Code:
cmdMoveFirst_Click()
   rsDates.MoveFirst
   DisplayRecords rsDates!voucherdate
End Sub

cmdMoveNext_Click()
   if rsDates.EOF or rsDates.BOF then
      rsDates.MoveFirst
   Else
      rsDates.MoveNext
   EndIf

   DisplayRecords rsDates!voucherdate
End Sub

cmdMovePrevious_Click()
   if rsDates.EOF or rsDates.BOF then
      rsDates.MoveLast
   Else
      rsDates.MovePrevious
   EndIf

   DisplayRecords rsDates!voucherdate
End Sub

cmdMoveLast_Click()
   rsDates.MoveLast
   DisplayRecords rsDates!voucherdate
End Sub

Private Sub DisplayRecords(ByVal VoucherDate as String)
   rsVouchers.Open "SELECT * FROM Salesvoucher WHERE voucherdate='" & VoucherDate & "'",ConnectionObject

'Code to dosplay records goes here.....

End Sub

Let me know how this works out.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top