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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Getting the correct rate to print

Author  Topic 

bi89405
Starting Member

35 Posts

Posted - 2008-12-19 : 10:38:35
I am fairly new to writing SQL as well as to this forum so I apologize if this sounds too fundamental but I really do need someone's help.

I have a table that contains all our employee's historical rates. The only values in this table is the effective date and the rate. The effective date will always be the first of the month. It looks something like this:

Date Rate
01/01/2008 $100
04/01/2008 $200
06/01/2008 $400

The rates increase as the level of experience of the employee grows.

I also have a transaction table that stores the date & the hours worked by each employee. This table contains 2 fields; work date & hours. The work date can be any date within the year and not necessarily the first of each month, it can be 05/14/2008 as an example.

How can I write a stored procedure that will look at the work date, determine which rate should be applied to the transaction. Using the table above, if the employee worked on 01/21/2008, the rate returned for that transaction should be $100 and if the same employee worked on 04/26/2008, the rate returned should be $200, etc.

I would like the stored procedure to contain the following fields,
work date, hours, rate, (value)

value which is the determined rate * the hours worked.

Can someone please help?

Thanks.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-19 : 10:40:44
See http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -