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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query Help

Author  Topic 

tlug
Starting Member

21 Posts

Posted - 2012-02-24 : 13:20:49
Hello,

I am working on a query that I need some help with.. I know it is likely something really simple that I have overlooked and just can't get it the way I want it..

Below is the data that the query is spitting out.. All I want is for it to Sum for each employee for the entire week, where as right now it shows to total for each day.

So for Janice Acosta it would read:
ACOSTA, JANICE 8900 8/5/11 REG 39:30:00

So I want it to total by Paycode for each employee.

ACOSTA, JANICE 8900 8/2/11 REG 7:59 AM
ACOSTA, JANICE 8900 8/3/11 REG 7:57 AM
ACOSTA, JANICE 8900 8/1/11 REG 7:53 AM
ACOSTA, JANICE 8900 8/5/11 REG 7:53 AM
ACOSTA, JANICE 8900 8/4/11 REG 7:48 AM
ADAM-ROSS, RACHAL F. 8450 8/5/11 OT15 12:44 AM
ADAM-ROSS, RACHAL F. 8450 8/3/11 REG 8:05 AM
ADAM-ROSS, RACHAL F. 8450 8/2/11 REG 8:05 AM
ADAM-ROSS, RACHAL F. 8450 8/4/11 REG 8:03 AM
ADAM-ROSS, RACHAL F. 8450 8/5/11 REG 7:19 AM
ADAM-ROSS, RACHAL F. 8450 8/1/11 REG 8:28 AM
ADAME, GRICELLE 20211 8/2/11 REG 8:04 AM
ADAME, GRICELLE 20211 8/1/11 REG 8:03 AM
ADAME, GRICELLE 20211 8/4/11 REG 8:12 AM
ADAME, GRICELLE 20211 8/3/11 REG 4:10 AM
ADAME, GRICELLE 20211 8/5/11 REG 6:15 AM
ADAME, GRICELLE 20211 8/3/11 VCHR 4:00 AM


Select 
Pay.[PERSONFULLNAME],
Pay.[PERSONNUM] as EmployeeID,
Pay.[applydate] as Week_Ending,
Pay.[PAYCODENAME]as Hours_Type,

CAST(Sum(CAST(Pay.TIMEINSECONDS AS FLOAT) /86400 ) AS FLOAT) AS timeInXLS

fROM [tkcsdb].[dbo].[VP_TOTALS]as Pay (NOLOCK)

Where applydate between '2011-07-31' and '2011-08-06'
and [LABORLEVELNAME2] = 'AUSTIN10380'
AND (Pay.PAYCODENAME NOT LIKE 'PCR%')
AND (Pay.PAYCODENAME NOT LIKE 'U%')
AND (Pay.PAYCODETYPE = 'P')

Group By
Pay.[PERSONFULLNAME],
Pay.[PERSONNUM],
Pay.[applydate],
Pay.[PAYCODENAME]

Order By
Pay.[PERSONFULLNAME],
Pay.[PAYCODENAME]


Thanks!

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-24 : 13:38:19
we need the data types..post the DDL

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

tlug
Starting Member

21 Posts

Posted - 2012-02-24 : 14:58:34
Everything is Text except for the last column... The timeinseconds is an integer.

Thanks!
Go to Top of Page

tlug
Starting Member

21 Posts

Posted - 2012-02-24 : 15:01:14
Actually sorry, obviously the date column is a date, the rest is all text except for the timeinseconds field which is an integer.

Thanks!
Go to Top of Page

tlug
Starting Member

21 Posts

Posted - 2012-02-24 : 15:49:32
I don't know how to create a DLL in SSMS.. But I am querying the data from a view..

[PERSONFULLNAME] is a varchar(64)
[PERSONNUM] is a varchar(15)
[applydate] is a datetime
[PAYCODENAME] is a varchar(50)
TIMEINSECONDS is an int

Im simply trying to total the number of hours for each employee.. So the query right now shows the total number of hours for each day, and I want the total number of hours..

I can't seem to figure out how to get to that next step where it just outputs the total hours instead of the hours for each day.

Thanks!
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-24 : 15:53:10
how do you determine number of hours now?

And you want it for...??? a week, a month, a year, YTD???

For each employee???



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

tlug
Starting Member

21 Posts

Posted - 2012-02-24 : 16:31:31
I figured out another way to do it.. But im still interested to see if there was another way to do it..

Im determining the hours by dividing the number of seconds by 86400 which puts the seconds into a decimal form and then you can just change the format to hours in Excel.

The reporting is for a week, and for each employee.

Thanks!
Go to Top of Page
   

- Advertisement -