Anti-Rich
Well-known member
hi everyone,
i have a problem at the moment, where i am trying to retrieve timesheet information (for the employees at my company) from the database. now i can get basic information, but i wanted (for comparitive purposes), to break it down to do it by month...
here is my query so far
when i run this query in the analyzer it returns incorrect results, in the way that if there are 5 entries from one person for january, it shows 5 rows, rather than 1 condensed row. what im trying to do is make it so that it returns a total hours worked, total overtime and total pay broken down month by month. i understand how distinct works (or at least i thought i did) but it doesnt seem to want to do what i want in this case. i dont understand why its returning x number of rows rather than just 1 per month.
if someone could offer any input id be greatly appreciative
cheers
adam
i have a problem at the moment, where i am trying to retrieve timesheet information (for the employees at my company) from the database. now i can get basic information, but i wanted (for comparitive purposes), to break it down to do it by month...
here is my query so far
VB.NET:
[SIZE=2][COLOR=#0000ff]select [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Distinct [/COLOR][/SIZE][SIZE=2][COLOR=#ff00ff]Month[/COLOR][/SIZE][SIZE=2][COLOR=#808080]([/COLOR][/SIZE][SIZE=2]t[/SIZE][SIZE=2][COLOR=#808080].[/COLOR][/SIZE][SIZE=2]tsDate[/SIZE][SIZE=2][COLOR=#808080])[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]as [/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]'Month'[/COLOR][/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] t[/SIZE][SIZE=2][COLOR=#808080].[/COLOR][/SIZE][SIZE=2]EmployeeID[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE]
[SIZE=2][COLOR=#ff00ff]Sum[/COLOR][/SIZE][SIZE=2][COLOR=#808080]([/COLOR][/SIZE][SIZE=2]t[/SIZE][SIZE=2][COLOR=#808080].[/COLOR][/SIZE][SIZE=2]RegularHours[/SIZE][SIZE=2][COLOR=#808080]) [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]AS [/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]'Total Regular Hours'[/COLOR][/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE]
[SIZE=2][COLOR=#ff00ff]Sum[/COLOR][/SIZE][SIZE=2][COLOR=#808080]([/COLOR][/SIZE][SIZE=2]t[/SIZE][SIZE=2][COLOR=#808080].[/COLOR][/SIZE][SIZE=2]Overtime[/SIZE][SIZE=2][COLOR=#808080]) [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]as [/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]'Total Overtime Hours'[/COLOR][/SIZE][SIZE=2][COLOR=#808080], [/COLOR][/SIZE][SIZE=2][COLOR=#ff00ff]sum[/COLOR][/SIZE][SIZE=2][COLOR=#808080]([/COLOR][/SIZE][SIZE=2]t[/SIZE][SIZE=2][COLOR=#808080].[/COLOR][/SIZE][SIZE=2]TotalPay[/SIZE][SIZE=2][COLOR=#808080]) [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]AS [/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]'Total Paid'[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]FROM[/COLOR][/SIZE][SIZE=2] tblEmployeeTimeSheet t [/SIZE][SIZE=2][COLOR=#808080]INNER [/COLOR][/SIZE][SIZE=2][COLOR=#808080]JOIN[/COLOR][/SIZE][SIZE=2] tblEmployee e [/SIZE]
[SIZE=2][COLOR=#0000ff]ON[/COLOR][/SIZE][SIZE=2] t[/SIZE][SIZE=2][COLOR=#808080].[/COLOR][/SIZE][SIZE=2]EmployeeID [/SIZE][SIZE=2][COLOR=#808080]=[/COLOR][/SIZE][SIZE=2] e[/SIZE][SIZE=2][COLOR=#808080].[/COLOR][/SIZE][SIZE=2]EmployeeID [/SIZE][SIZE=2][COLOR=#0000ff]GROUP [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]BY[/COLOR][/SIZE][SIZE=2] e[/SIZE][SIZE=2][COLOR=#808080].[/COLOR][/SIZE][SIZE=2]EmployeeID[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] t[/SIZE][SIZE=2][COLOR=#808080].[/COLOR][/SIZE][SIZE=2]EmployeeID[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] t[/SIZE][SIZE=2][COLOR=#808080].[/COLOR][/SIZE][SIZE=2]tsDate[/SIZE]
when i run this query in the analyzer it returns incorrect results, in the way that if there are 5 entries from one person for january, it shows 5 rows, rather than 1 condensed row. what im trying to do is make it so that it returns a total hours worked, total overtime and total pay broken down month by month. i understand how distinct works (or at least i thought i did) but it doesnt seem to want to do what i want in this case. i dont understand why its returning x number of rows rather than just 1 per month.
if someone could offer any input id be greatly appreciative
cheers
adam