Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How automatically add 1 year date to an existing date in SQL Server

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

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

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

I have my algorithm like this:

  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.

Please how do I write the script?

like image 538
Rahmat Avatar asked Feb 09 '12 14:02

Rahmat


People also ask

How do I insert an automatic date in SQL?

To insert only date value, use curdate() in MySQL. With that, if you want to get the entire datetime, then you can use now() method. Insert both date and time with the help of now().


1 Answers

Use DATEADD, i.e.:

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

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

like image 97
JScoobyCed Avatar answered Sep 21 '22 10:09

JScoobyCed