Jacksparrow87
Technical User
Hi people,
I was hoping someone could offer me some help please, I have two select statements which work and show me different information but how do I join them to show the information I need?
The first select statement is as follows:
"Select [Company], [ChaCode], COUNT(ChaCode) As NumberofChargeCodes, SUM(TSpent) As SumofTimeSpent From Log where Dol BETWEEN ? AND ? And CompID = ? Group By [Company], [ChaCode]"
The second statement is:
"Select [Company], [ChaCode], COUNT(ChaCode) As [NumberofChargeCodes] From Log where Dol BETWEEN ? AND ? And CompID = ? And NoteNumber = 1 Group By [Company], [ChaCode]"
What I want to show is the same data as select statement 2 (only where Notenumber = 1) however I want to include the Sum TSpent for all the data (not only where notenumber = 1). For example something like the following:
"Select [Company], [ChaCode], COUNT(ChaCode) As NumberofChargeCodes, SUM(TSpent) As SumofTimeSpent From Log where Dol BETWEEN ? AND ? And CompID = ? And NoteNumber = 1 Group By [Company], [ChaCode]"
However the trouble with the above statement is that it calculates the SUM of TSpent only from notenumber1 where it should calculate it from all rows.
If you dont understand please tell me, thanks.
I was hoping someone could offer me some help please, I have two select statements which work and show me different information but how do I join them to show the information I need?
The first select statement is as follows:
"Select [Company], [ChaCode], COUNT(ChaCode) As NumberofChargeCodes, SUM(TSpent) As SumofTimeSpent From Log where Dol BETWEEN ? AND ? And CompID = ? Group By [Company], [ChaCode]"
The second statement is:
"Select [Company], [ChaCode], COUNT(ChaCode) As [NumberofChargeCodes] From Log where Dol BETWEEN ? AND ? And CompID = ? And NoteNumber = 1 Group By [Company], [ChaCode]"
What I want to show is the same data as select statement 2 (only where Notenumber = 1) however I want to include the Sum TSpent for all the data (not only where notenumber = 1). For example something like the following:
"Select [Company], [ChaCode], COUNT(ChaCode) As NumberofChargeCodes, SUM(TSpent) As SumofTimeSpent From Log where Dol BETWEEN ? AND ? And CompID = ? And NoteNumber = 1 Group By [Company], [ChaCode]"
However the trouble with the above statement is that it calculates the SUM of TSpent only from notenumber1 where it should calculate it from all rows.
If you dont understand please tell me, thanks.