|
I have two tables called TimeCardHours and Employee. Below are the structure of those. Now I have a question like below: The total cost in TimeCardHourse should be automatically calculated using the formula (Billable hours * Billing rate for the employee to whom the time card is issued.) I gave a big try to do this, but I failed. please help me..Please..
(comments are locked)
|
|
OK. Computed Column doesn't appear to do what you need (a sub-query). Other options:
I would probably go for the Trigger in this situation, just to ensure that the calculations are performed as they should be during normal operations (assuming normal operations doesn't include bulk loading this table). You should also consider putting a "billed" field on the TimeCardHours table, so that the trigger knows not to update the costs on that one... @Grant - thanks for the Thumbs-Up! That pushed me over 1k rep...
Jul 23 '10 at 03:49 AM
ThomasRushton ♦
(comments are locked)
|
|
I would suggest moving the BillingRate into a separate table with ValidFrom and ValidTo to cover the possibility of a changing BillingRate. I prefer the view to a trigger/sproc, as a calculated value like this can change so often. Another possibility is storing the billing rate in the TimCardsHours table directly with the BillableHours and then creating a computed column for that. That's why I like these questions - you get several different options to think about, and it shows how different approaches can be used. All in, this place is a great place to learn!
Jul 23 '10 at 01:43 AM
ThomasRushton ♦
(comments are locked)
|
|
As an evil way to do this, you could put the calculation in a user defined function and call that as part of your computed column. However, this would be entirely evil when used in a large data scenario. Functions are bad enough for performance, let alone ones which do data lookups. But, it is an option. Too true RE evil! Beelzebub would be proud ;-)
Jul 23 '10 at 06:56 AM
WilliamD
(Irrelevant mental meandering - I now have Queen's Bohemian Rhapsody in my head. And I've got a three hour drive to get home, with no CD / MP3 player. I'll just have to see what the BBC can offer up...)
Jul 23 '10 at 07:31 AM
ThomasRushton ♦
Thomas, so it'll be a pretty "Wayne's Worldy" drive for you...
Jul 23 '10 at 07:39 AM
WilliamD
:-) A certain amount of headbangery - the music sampled ranged from a Mozart string quartet through to some popular young musicians scouting for girls. Or something. I'm getting old, you know... (BBC Radios 3 & 2. Got home before I needed to switch to BBC Radio 4 for "The Now Show")
Jul 23 '10 at 12:00 PM
ThomasRushton ♦
(comments are locked)
|
|
you can create a view for this What if the billing rate for an employee changes?
Jul 23 '10 at 01:15 AM
ThomasRushton ♦
that is for sepala to answer. It really depends on what is the business rule
Jul 23 '10 at 04:20 AM
Squirrel
(comments are locked)
|

