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

后端 未结 3 1098
抹茶落季
抹茶落季 2021-01-18 12:16

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

<
相关标签:
3条回答
  • 2021-01-18 12:35

    there should be .add or addyear() function in sql. You add like .add(year, day, month). Read upon sql datetime add year, month and seconds. It is pretty straightforward. It is just like c#.

    Dateadd(info). now time is. getdate().

    0 讨论(0)
  • 2021-01-18 12:47

    Use DATEADD, i.e.:

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

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

    0 讨论(0)
  • 2021-01-18 12:50

    Assuming the columns of the 2 tables are the same:

    INSERT INTO PatientDebit
    SELECT * from PatientsInfo WHERE DateCreated<DATEADD(year, -1, GETDATE())
    

    Make sure you have an index on DateCreated if PatientsInfo has a lot of records as it could potentially be slow otherwise

    0 讨论(0)
提交回复
热议问题