如何自动将 1 年日期添加到 SQL Server 中的现有日期 [英] How automatically add 1 year date to an existing date in SQL Server

查看:31
本文介绍了如何自动将 1 年日期添加到 SQL Server 中的现有日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一项任务是根据 DateCreated 列自动向 PatientsInfo 表中的所有注册患者收取 N2,500 的年度账单.

I have a task to automatically bill all registered patients in PatientsInfo table an Annual Bill of N2,500 base on the DateCreated column.

当然,我将使用存储过程将这些记录插入到PatientDebit 表中,并创建一个 SQL 作业来执行此过程.

Certainly I will use a stored procedure to insert these records into the PatientDebit table and create a SQL Job to perform this procedure.

我将如何在 PatientsInfo 表中 select * 患者,其中 DateCreated 现在是 1 岁让我插入另一个表 PatientDebit.

How will I select * patients in PatientsInfo table where DateCreated is now 1 yr old for me to insert into another table PatientDebit.

我的算法是这样的:

  1. PatientsInfo表中选择患者的注册日期
  2. 将 1 年添加到他们的 DateCreated
  3. 今天是否添加了日期?如果是,
  4. 将记录插入PatientDebit表中,帐单为N2,500
  5. 如果不是,什么都不做.
  1. select date of registration for patients from PatientsInfo table
  2. Add 1 year to their DateCreated
  3. Is date added today? if yes,
  4. Insert record into PatientDebit table with the bill of N2,500
  5. If no, do nothing.

请问我如何编写脚本?

推荐答案

使用 DATEADD,即:

Use DATEADD, i.e.:

SELECT DATEADD(year, 1, '2006-08-30')

参考:http://msdn.microsoft.com/en-us/library/ms186819.aspx

这篇关于如何自动将 1 年日期添加到 SQL Server 中的现有日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆