Shoutbox

database help - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: database help (/showthread.php?tid=55892)

database help by spokes on 02-15-2006 at 05:33 PM

ok, im using access and in one table i have these 2 fields

LastUpdated and DateRegistered

now, ive made a 3rd field DaysLeftToRenew, the basic idea is that membership has to be renewed once a year, how can i display how many days that member has left to renew their membership in this field?

thanks


RE: database help by Adeptus on 02-17-2006 at 02:42 PM

Hi,

You don't need an additional column in your database table for this -- you can compute it at any time, from what's already there. Use SQL functions datediff(), dateadd() and getdate().  The query might look something like this:

select DateRegistered, LastUpdated, datediff('d', getdate(), dateadd('yyyy', 1, LastUpdated)) as DaysLeftToRenew from MyTable

The above would evaluate to the difference (in days) between the current date and LastUpdated + one year, which sounds like what you want. 


RE: database help by RaceProUK on 02-17-2006 at 02:57 PM

SQL is a surprisingly powerful language, with many useful functions that allow you to use derived fields. If you must have an actual field though, then just set up a cron job to daily update that field.


RE: database help by Adeptus on 02-17-2006 at 03:02 PM

quote:
If you must have an actual field though, then just set up a cron job to daily update that field.

If he wants to make it look like a table with a field, he can always create a view including the computed column...  :P
RE: database help by RaceProUK on 02-19-2006 at 10:47 PM

CREATE OR REPLACE VIEW MembershipDetails AS
SELECT LastUpdated, DateRegistered, datediff('d', getdate(), dateadd('yyyy', 1, LastUpdated)) as DaysLeftToRenew
FROM MemberList;

Should do the trick ;)