Auto update field on save

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
crash
User
Posts: 151

Auto update field on save

Post by crash »

I have two fields in a table <DOB> and <Age>
I'd like to update the Age after someone adds the user's DOB.

I've got this to work in a View but then I end up needing an extra table to see the calculation.

This is my code as an expression in the View.

DateDiff(MONTH, DOB, GetDate()) / 12 - Case When Month(DOB) = Month(GetDate()) And Day(DOB) > Day(GetDate()) Then 1 Else 0 End

How do I add this to the Table to update after saving.

Thanks


MichaelG
User
Posts: 1111

Post by MichaelG »

You should simply create the Age field that is calculated based on the Date of Birth in your database view. Please google for "Calculate age from date of birth in SQL" for examples.


crash
User
Posts: 151

Post by crash »

Thanks but where do I put my code. I want the age to auto update. I did try add this as an expression in my field in the primary table but it does not auto update.

Or do you mean it must be done in my sql code in my database…


MichaelG
User
Posts: 1111

Post by MichaelG »

do you mean it must be done in my sql code in my database

Yes, it is the better way.


Post Reply