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 |
vani_r14
Starting Member
24 Posts |
Posted - 2008-03-26 : 23:07:26
|
Hi I am currently trying to calculate YTD for hours worked.the table currently has a column called hours worked for each person.so it currently looks like Name Mth1 Mth2 YTD Toys 40 30Cushions 30 40Tables 10 4papers 20 10I need help working out the YTD for the time frame entered by the manager who needs the report generatedcan some one please shed some light on how to do itI read something about the YTD Function...Thanks in advance :) Vani |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-03-26 : 23:11:48
|
What does Mth1 , Mth2 represent? How does it correspond to a time frame entered?It's more usual to have the month start date or yymm for a month - and also to have them in separate rows rather than as columns.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
vani_r14
Starting Member
24 Posts |
Posted - 2008-03-27 : 01:47:03
|
heithe mth1 and mth2 are meant to be month 1 and month2. let me clarify with this example that i am looking at as well...For instance if there are 5 employees working in department A3 and they all have a certain hours that they have worked which are charged. Name Hrs_Wked Hrs_Wked Hrs_Wked Mitchell 60 59 40 Toby 56 52 67 Rito 65 56 65 Tori 76 56 54 ….…..(PS I have put them in columns for easy reading, and other months have values as well)all i need to do is calculate the year to date for each employee for the period needed.could someone please helpthanks in advance |
 |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-03-27 : 02:47:13
|
What is month 1? i.e. when does your period start?It's still a bad design can you change it to:EmployeeMonth_yymmHoursthen the query becomes fairly trivial - also a lot easier to populate the table too.Otherwise it's probably best to transform your data before doing the query - but you'll need a way to know what date month 1 starts on.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
vani_r14
Starting Member
24 Posts |
Posted - 2008-03-27 : 16:01:46
|
hei- The month1 starts on the 1st of April 08. - so the year goes from the 1st of April to 31st of march 09- |
 |
|
|
|
|