1

I have this big database table that contains 12 medical ceritifcations, expiration dates, links to files and what companies they're from. I need to generate a report via email within 90,60,30 and 15 days of the the certification expiring date.

Here's what the datebase looks like:

certID,
profileID,
cprAdultExp,
cprAdultcompany,
cprAdultImage,
cprAdultOnFile,
cprInfantChildExp,
cprInfantChildcompany,
cprInfantChildImage,
cprInfantChildOnFile,
cprFPRExp,
cprFPRcompany,
cprFPRImage,
cprFPROnFile,
aedExp,
aedcompany,
aedImage,
aedOnFile,
firstAidExp,
firstAidcompany,
firstAidImage,
firstAidOnFile,
emtExp,
emtcompany,
emtImage,
emtOnFile,
waterSafetyInstructionExp,
waterSafetyInstructioncompany,
waterSafetyInstructionImage,
waterSafetyInstructionOnFile,
bloodPathogensExp,
bloodPathogenscompany,
bloodPathogensImage,
bloodPathogensOnFile,
oxygenAdminExp,
oxygenAdmincompany,
oxygenAdminImage,
oxygenAdminOnFile,
lifegaurdingExp,
lifegaurdingcompany,
lifegaurdingImage,
lifegaurdingOnFile,
wildernessResponderExp,
wildernessResponderCompany,
wildernessResponderImage,
wildernessResponderOnFile, 
notes

How do I write some sort of loop to check all the dates (anything with EXP is a date) then store which ones are expiring, and email all those details to a person?

4

3 回答 3

2

由于您必须通过 CF 发送电子邮件(我想),所以我的处理方法是每天运行一次计划任务,检查哪些行有 15、30、60 和 90 天的到期周年纪念日。因此,计划任务将运行一些查询,然后发送电子邮件。

第一件事是实际找到有问题的行(我所有的 SQL 都假定 MS SQL Server - 其他 RDBMS 将具有类似的语法):

<cfquery name="qExpiring">
  select
  certID,  
  dateDiff(day, cprAdultExp, getDate()) as cprAdultExpDaysSince
  dateDiff(day, cprInfantChildExp, getDate()) as cprInfantChildExpDaysSince
  from yourTable
  where 
  dateDiff(day, cprAdultExp, getDate()) in (15, 30, 60, 90)
  or 
  dateDiff(day, cprInfantChildExp, getDate()) in (15, 30, 60, 90)
</cfquery>

这应该给你一个像这样的结果集:

certID|cprAdultExpDaysSince|cprInfantChildExpDaysSince|etc.
___________________________________________________________
xxxxxx|30                  |5                         |etc.
xxxxxx|16                  |60                        |etc.
xxxxxx|2                   |90                        |etc.

任何在 15、30、60、90 上匹配的内容,您有兴趣进一步处理。您可以使用查询查询来执行此操作:

<cfquery name="qAdultExpRenewal" dbtype="query">
  select * from qExpiring
  where cprAdultExpDaysSince in (15, 30, 60, 90)
</cfquery>

然后您 cn 遍历这些记录并根据 的值发送适当的电子邮件cprAdultExpDaysSince

您缺少一些信息来给您一个全面的答案,但我希望这将为您指明正确的方向。

于 2011-01-15T12:55:03.337 回答
1

如果您有权访问数据库,您可能应该创建一个或多个视图,只为您提供那些即将到期的视图或添加一个字段数天直到每个证书到期并查询该字段。或者,您可以编写一个查询来获取任何证书即将到期的所有信息(WHERE cprAdultExp [comparison] 日期或 cprInfantExp [comparison] 日期....),然后遍历记录以过滤或按证书到期分组。

于 2011-01-14T21:43:05.297 回答
1

您可能想要某种看起来像的愚蠢的巨大查询

select "CPR Adult", cprAdultExp, cprAdultcompany, cprAdultImage, cprAdultOnFile from thebigtable where cprAdultExp [comparison] interestingdate
union
select "CPR Child", cprChild....
union ...

然后遍历您返回的行,使用第一列来指示哪些认证即将到期。

于 2011-01-14T20:54:42.787 回答