Jacksparrow87
Technical User
Hi people,
I was hoping someone could offer me some help on my select statement. First I will try to explain how my data is shown:
My table looks like as follows:
LogNumber, NoteNumber, Company, ChargeCode, Date, Time Spent, etc
1,3Adidias,then the other info in all of the rows.
1,2Adidas
1,1Adidas
2,4Nike
2,3Nike
2,2Nike
2,1Nike
3,3Reebok
3,2Reebok
3,1Reebok
4,3Umbro
4,2Umbro
4,1Umrbo
What I need help with is basically on the statistics part of my program, I want the user to choose a date from dtp1 and dtp2 (Date from and Date to), then I want the user to choose a company. Once they have chosen all of the above and clicked on search I want to execute my select statement, however I want the answer counted up for example as follows:
Company, Chargecode, Number of calls with charge codes
Adidas, RSA, 5
Adidas, RST, 6
Adidas, RAG, 9
Adidas, TSA, 10
Now comes the hard part, as the same charge code is assigned to each log (so every same lognumber has the same charge code), I only really want to count the charge code once rather than each time from the same log number. On top of this the date format of my dtp is dd/mm/yyyy however the data shown in the datagrid is like dd/mm/yyyy hh:mm, so I dont know how I would do that.
So far I have the following select statement:
However all this does is show all the maximum notenumber for everyone.
Any help please?
I was hoping someone could offer me some help on my select statement. First I will try to explain how my data is shown:
My table looks like as follows:
LogNumber, NoteNumber, Company, ChargeCode, Date, Time Spent, etc
1,3Adidias,then the other info in all of the rows.
1,2Adidas
1,1Adidas
2,4Nike
2,3Nike
2,2Nike
2,1Nike
3,3Reebok
3,2Reebok
3,1Reebok
4,3Umbro
4,2Umbro
4,1Umrbo
What I need help with is basically on the statistics part of my program, I want the user to choose a date from dtp1 and dtp2 (Date from and Date to), then I want the user to choose a company. Once they have chosen all of the above and clicked on search I want to execute my select statement, however I want the answer counted up for example as follows:
Company, Chargecode, Number of calls with charge codes
Adidas, RSA, 5
Adidas, RST, 6
Adidas, RAG, 9
Adidas, TSA, 10
Now comes the hard part, as the same charge code is assigned to each log (so every same lognumber has the same charge code), I only really want to count the charge code once rather than each time from the same log number. On top of this the date format of my dtp is dd/mm/yyyy however the data shown in the datagrid is like dd/mm/yyyy hh:mm, so I dont know how I would do that.
So far I have the following select statement:
Code:
Private Sub LoadLog()
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & Application.StartupPath & "\CNS.mdb")
Dim adapter As New OleDbDataAdapter("Select Log.* from Log, (select lg.LogNumber, Maxlg.NoteNumber) as MaxNN from Log lg group by lg.LogNumber) temp where Log.LogNumber = temp.LogNumber and Log.NoteNumber = temp.MaxNN order by Log.LogNumber ", conn)
Dim dt As New DataTable("Log")
adapter.Fill(dt)
dglog.DataSource() = dt
dt.DefaultView.AllowNew = False
End Sub
However all this does is show all the maximum notenumber for everyone.
Any help please?