Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7693563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:07:06+00:00 2026-05-31T21:07:06+00:00

Before anything else, here is the simplified schema ( with dummy records ) of

  • 0

Before anything else, here is the simplified schema (with dummy records) of the database:

ItemList

ItemID     ItemName     DateAcquired     Cost       MonthlyDep    CurrentValue
================================================================================
1          Stuff Toy    2011-12-25       100.00         10.00         100.00
2          Mouse        2011-12-23       250.00         50.00         200.00
3          Keyboard     2011-12-17       250.00         30.00         190.00
4          Umbrella     2011-12-28       150.00         20.00         110.00
5          Aircon       2011-12-29       950.00         25.00         925.00

DepreciationTransaction

ItemID     DateOfDep       MonthlyDep     
======================================
2          2012-01-31         250.00
3          2012-01-31          30.00
4          2012-01-31          20.00
5          2012-01-31          25.00
3          2012-02-29          30.00
4          2012-02-29          20.00

I need your suggestions to help me solve this problem. Basically I am creating a depreciation monitoring system of a certain LGU. The problem of the current database is that it lacks some records for a specific date of depreciation, for instance:

Lacking Records (this is not a table from the database)

ItemID      LackingDate
============================
1            2012-01-31
1            2012-02-29
2            2012-02-29
5            2012-02-29

And because of the lacking records, I cannot generate the depreciation report for the month of MARCH. Any idea how can I insert missing records on the DepreciationTransaction?

What have I done so far? None. But a simple query that calculates the newly depreciated value (which produces incorrect value because of the missing records)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:07:08+00:00Added an answer on May 31, 2026 at 9:07 pm

    The problem here is that you will have to generate data. MySQL is not intended to generate data, you should do that at an application level and just tell MySQL to store it. In this case, the application should check wether there are missing records and create them if needed.

    Leaving that aside, you can (awfully) create dynamic data with MySQL like this:

    select il.itemId, endOfMonths.aDate from ((
      select aDate from (
        select @maxDate - interval (a.a+(10*b.a)+(100*c.a)+(1000*d.a)) day aDate from
        (select 0 as a union all select 1 union all select 2 union all select 3
         union all select 4 union all select 5 union all select 6 union all
         select 7 union all select 8 union all select 9) a, /*10 day range*/
        (select 0 as a union all select 1 union all select 2 union all select 3
         union all select 4 union all select 5 union all select 6 union all
         select 7 union all select 8 union all select 9) b, /*100 day range*/
        (select 0 as a union all select 1 union all select 2 union all select 3
         union all select 4 union all select 5 union all select 6 union all
         select 7 union all select 8 union all select 9) c, /*1000 day range*/
        (select 0 as a union all select 1 union all select 2 union all select 3
         union all select 4 union all select 5 union all select 6 union all
         select 7 union all select 8 union all select 9) d, /*10000 day range*/
        (select @minDate := (select min(dateAcquired) from il),
                @maxDate := '2012-03-01') e
      ) f
      where aDate between @minDate and @maxDate and aDate = last_day(aDate)
    ) endOfMonths, il)
    left join dt
    on il.itemId = dt.itemId and endOfMonths.aDate = dt.dateOfDep
    where dt.itemId is null and last_day(il.dateAcquired) < endOfMonths.aDate
    

    Depending on the length of the date range you can reduce the amount of dynamically generated results (10000 days means over 27 years of records each representing one day) by removing tables (d, c, b and a) and removing them from the upper formula. Setting the @minDate and @maxDate variables will allow you to specify the dates between you want to filter the results. This dates should be the min date from which you have an item and the max date should be march, in your case.

    In plain english: If select min(dateAcquired) from il returns a date before '2012-03-01' - 10000 days then you’ll have to add another union.

    Finally, just add the insert statement (if you really need to insert those records).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a custom validator which doesn't do anything before the user
I need to convert a string to another which has removed anything before the
Has anyone seen this before - and can anything be done about it? This
If in C I write: int num; Before I assign anything to num ,
Before you answer this I have never developed anything popular enough to attain high
Is there anything I should know before converting a large C++ program from VS2005
Is there anything special I have to do to a JSON object before I
I've been given some code with commenting unlike anything I've come across before: //{{{
I'm designing a game server and I have never done anything like this before.
Excuse me if this has indeed been asked before, I couldn't see anything that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.