tags:

views:

70

answers:

2

Hi all. This is my initial question....well I got a response but I'm still stuck. Can anyone please explain how can I achieve this in mysql:

I have two fields in mysql, 'cap_commdate' with DATE TYPE and 'cap_policyterm' with INT TYPE. I want to have another field called 'cap_maturityDate' which will automatically compute the policy term pereod in years (in layman's term ie: cap_commdate*cap_policyterm). What is the right SQL query to use; or what is the best approach; and I want to use it in my recordset to prepare a confirmation page... please a simple explanation...

I have tried the following:

SELECT DATE_ADD(cap_commdate, INTERVAL cap_policyterm YEAR) ...

I ran the query and got errors; so i edited it and used:

SELECT
DATE_ADD("cap_commdate", INTERVAL "cap_policyterm" YEAR) AS cap_maturity FROM capital

All I got was empty fields. Please help out.

+1  A: 

It sounds like you want this:

SELECT DATE_ADD(cap_commdate, INTERVAL cap_policyterm YEAR)
...

This DATE_ADD function adds the given number of years to the starting date, thus producing the maturity date — just as you've described.

VoteyDisciple
A: 

Please show the errors you get. The query

SELECT DATE_ADD(cap_commdate, INTERVAL cap_policyterm YEAR) FROM capital

should work.