• Mr. Celko,

    The main problem in here wouldn't be the DDL as we cannot see the original table just a simplified version of it. I'm pretty sure the OP shouldn't be changing the database structure one table at a time, that's just pointless and would imply lots of work on SQL Server and on the front ends. If you can't give a solution (or read the problem), please avoid posting anything. I'm sure that when someone wants to design a database with little knowledge on database design, they can go to the Stairway you wrote.

    To Thomas,

    I'm having some trouble with your posts, as there are three main problems I found:

    1. Your calculations are wrong or have some logic you didn't post (48 times 112.47 equals 5398.56 not 5398 and 508.61 times 5 equals 2543.05 not 2540) it might seem very few difference, but it's still a difference.

    2. Your values are declared int but you might want to use a numeric/decimal data type to avoid truncation.

    3. Your dates can have some trouble since DATEDIFF( mm, ' 20080229', '20120229') will give 49 and not 48. (I'm sure this was happening on a 2005 version, but I'm trying to reproduce this problem and won't happen in 2012 but I don't have a 2008 here).

    Be sure to test each part of your code before using it. And take care of your math.;-)

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2