• anthony.green - Tuesday, February 21, 2017 7:54 AM

    Hi All

    Bit of a mental block, probably from looking at this a bit to much, so any assistance is greatly appreciated.

    Attached is some sample data. expected results and my work in progress so far.

    I'm after a grand running total based on the apportionments.

    So for ID 4, I need the sum of everything from SeqNo 4 to 70
    For ID 1309, I need the sum of everything from SeqNo 3 to 52, 54 to 64, 66 to 68, 70 to 71, 73 to 75

    Each batch for the sum is started at the row before with its apportionment title and 100%, with the very last row of all apportionments being "Non Apportioned Expenditure"

    If a user adds a new Charge to an apportionment then the SeqNo's will remain consecutive, and any other apportion SeqNo's will increment, like a row_number, eg for ID 1309, user may add a new charge under "Schedule - All Tenants", which will mean the values will change to 3-53, 55-64, 67-69, 71-72, 74-76.

    Thanks
    Ant

    Thisnon-table mean makes no sense. There is no such thing in RDBMS as ageneric magical universal “<nothing in particular>_idâ€; bythe law of identity the foundations of basic logic it has to be anidentifier of something in particular.

    Bydefinition, a table must have a key. Yet you post things that cannever, ever have a key, because all the columns are NULL.

    Yourinsanely large “description_<nothing in particular>†seemsto be a code or type of transaction. We both know that your choice ofan insanely large VARCHAR(50) involved no research or planningwhatsoever. If you done it right. By the way there would be a checkconstraint limiting this column to the valid values that could fit init.

    Thereis no such crap as a “sequence_nbr†in in RDBMS; it has to be a“<something in particular>_seqâ€, such as invoices, checks,whatever. You might want to look up the create sequence statement inSQL. If this actually is a sequence.

    Whydo you think budget is a valid data element name? Is it a type code?A quantity? What?

    Whydo you think “apportion†(of what?) is a valid data element name?It looks to be a quantity, but it lacks what ISO 11179 calls anattribute property.

    Finally,“nominal†is an adjective, not even a noun! I also see that it ishuge. Were these the defaults from an old ACCESS or Xbase schema?

    Myguess is that the key is (generic_id, something_seq), but I have noconstraints or proof that this guess is correct.

    Mostof the work in SQL is done in the DDL, so I would suggest you throwout what you have got and start over with the correct design. Thislooks like someone transcribed a series of notes of a yellow pad intoan improper table declaration. Would you like to try again?

    Thisnon-table mean makes no sense. There is no such thing in RDBMS as ageneric magical universal “<nothing in particular>_idâ€; bythe law of identity the foundations of basic logic it has to be anidentifier of something in particular.

    Bydefinition, a table must have a key. Yet you post things that cannever, ever have a key, because all the columns are NULL.

    Yourinsanely large “description_<nothing in particular>†seemsto be a code or type of transaction. We both know that your choice ofan insanely large VARCHAR(50) involved no research or planningwhatsoever. If you done it right. By the way there would be a checkconstraint limiting this column to the valid values that could fit init.

    Thereis no such crap as a “sequence_nbr†in in RDBMS; it has to be a“<something in particular>_seqâ€, such as invoices, checks,whatever. You might want to look up the create sequence statement inSQL. If this actually is a sequence.

    Whydo you think budget is a valid data element name? Is it a type code?A quantity? What?

    Whydo you think “apportion†(of what?) is a valid data element name?It looks to be a quantity, but it lacks what ISO 11179 calls anattribute property.

    Finally,“nominal†is an adjective, not even a noun! I also see that it ishuge. Were these the defaults from an old ACCESS or Xbase schema?

    Myguess is that the key is (generic_id, something_seq), but I have noconstraints or proof that this guess is correct.

    Mostof the work in SQL is done in the DDL, so I would suggest you throwout what you have got and start over with the correct design. Thislooks like someone transcribed a series of notes of a yellow pad intoan improper table declaration. Would you like to try again?

    Please post DDL and follow ANSI/ISO standards when asking for help.