0

I am stuck in a case that on my financial sys, I need to add a option for value to be monthly, weekly or every 2 weeks

example:

DESC    |   VALUE |    DATEADD |  FREQUENCY
--------+---------+------------+-----------
SALARY  | 1000,00 | 26/03/2017 |         30 (MONTHLY)
DINNER  |   50,00 | 26/03/2017 |          7 (WEEKLY)
BUSTICK |   75,00 | 26/03/2017 |         15 


select 
    * 
from 
    tableexpensives 
where 
    datesys between '01/01/2017' and '31/12/2017'

so it should show on sql

APR | SALARY   | 1000,00 | (1x month)
APR | DINNER   |  200,00 | (4x month)
APR | BUSTICK  |  150,00 | (2X month)
MAI | SALARY   | 1000,00 | (1x month)
MAI | DINNER   |  200,00 | (4x month)
MAI | BUSTICK  |  150,00 | (2X month)
....

Any idea how to do that?

2
  • One suggestion: if you want something 1x month, 2x month and 4x month, it is easier to represent it with 1, 2 and 4 than with 30, 7, 15. And one question: you want what you add it in 26/3/2017 to be "repreated every month and forever"?
    – joanolo
    Commented Mar 26, 2017 at 22:36
  • hi, sorry for the delayed on my reply, but I haven't been notified that were answers. anyway, basically, I want the user add an expensive value and frequency how ofter it will be appear. so if it is monthly, it will apear monthly forever til I delete it or change it. I Need to prepare a flow that, when I request the flow of Incoming and Outcoming of money, for the payments on the system, some of them will be 4 parcels and finish other will be every month... do you know what I mean? thanks
    – Hermeson
    Commented Mar 30, 2017 at 13:53

1 Answer 1

0

Your question is not 100% clear, and I'm proposing a tentative answer using PostgreSQL (I don't have FireBird installed at the moment). The concepts are the same regardless of database make.

1st: I would represent data in an easier way:

CREATE TABLE expenses
(
    description varchar, 
    amount numeric(10,2), 
    dateadd date, 
    times_per_month numeric(10, 0)
) ;

INSERT INTO expenses
    (description, amount, dateadd, times_per_month)
VALUES
    ('SALARY',    1000.00, '2017-03-26', 1),
    ('DINNER',      50.00, '2017-03-26', 4),
    ('BUSTICK',     75.00, '2017-03-26', 2) ;

From this point on, and assuming you would like this data to appear under the heading MARCH (and not APRIL, MAY, ... forever), you would just use something very simple: a multiplication.

SELECT
  to_char(dateadd, 'MON') AS month,
  description,
  (amount * times_per_month) AS subtotal
FROM
  expenses ;

And you'd get:

| month | description | subtotal |
|-------|-------------|----------|
|   MAR |      SALARY |     1000 |
|   MAR |      DINNER |      200 |
|   MAR |     BUSTICK |      150 |

Check it at: http://sqlfiddle.com/#!15/34efd/1/0

1
  • hi, sorry for the delayed on my reply, but I haven't been notified that were answers. anyway, basically, I want the user add an expensive value and frequency how ofter it will be appear. so if it is monthly, it will apear monthly forever til I delete it or change it. I Need to prepare a flow that, when I request the flow of Incoming and Outcoming of money, for the payments on the system, some of them will be 4 parcels and finish other will be every month... do you know what I mean? thanks
    – Hermeson
    Commented Mar 30, 2017 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.