Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
FernandoLorival
Starting Member
19 Posts |
Posted - 2008-07-01 : 17:10:50
|
| Hi all,I need to determine the number of days that an employee worked.For that I rely on the production database that gives me the production for that employee during a period of time.For that i have :SELECT CONVERT(Varchar,EventStart,101) AS DATEFROM [Ontegra-Production].[dbo].[tbl_Machine_Events_History]WHERE Shift = '2' AND CONVERT(Varchar,EventStart,101) >= '06/20/2008' AND CONVERT(Varchar,EventEnd,101) <= '06/30/2008' GROUP BY CONVERT(Varchar,EventStart,101) ORDER BY CONVERT(Varchar,EventStart,101) ASCThe result is:Date-------06/20/200806/21/200806/22/200806/23/200806/25/2008So I know that he worked 5 days!Now I need to multiply by the number of hours on that shift...The problem is I can't retrive that number (5)!!!!!!That must be very easy but I cant find a way of counting those days... DawwwThank you for the help. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-01 : 17:13:39
|
| SELECT COUNT(CONVERT(Varchar,EventStart,101)) AS DATEFROM [Ontegra-Production].[dbo].[tbl_Machine_Events_History]WHERE Shift = '2' AND CONVERT(Varchar,EventStart,101) >= '06/20/2008' AND CONVERT(Varchar,EventEnd,101) <= '06/30/2008' GROUP BY CONVERT(Varchar,EventStart,101) ORDER BY CONVERT(Varchar,EventStart,101) ASCAlso dont convert dates to varcharsMadhivananFailing to plan is Planning to fail |
 |
|
|
FernandoLorival
Starting Member
19 Posts |
Posted - 2008-07-01 : 17:25:52
|
| Hi madhivanan,Thank you for your post...The way you have the query it will count the number of times the same date shows in the GROUP BY Clause not the number of times in the final result.Here is the result of that:DATE------101372515I just need a simple number.... 5 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-02 : 15:21:19
|
| SELECT COUNT(DATE) as counting from(SELECT CONVERT(Varchar,EventStart,101) AS DATEFROM [Ontegra-Production].[dbo].[tbl_Machine_Events_History]WHERE Shift = '2' AND CONVERT(Varchar,EventStart,101) >= '06/20/2008' AND CONVERT(Varchar,EventEnd,101) <= '06/30/2008' GROUP BY CONVERT(Varchar,EventStart,101) ) as tMadhivananFailing to plan is Planning to fail |
 |
|
|
FernandoLorival
Starting Member
19 Posts |
Posted - 2008-07-02 : 16:00:16
|
| Excellent...Thank you Madhivanan! |
 |
|
|
|
|
|
|
|