Sql server 如何批量更新日期列

Sql server 如何批量更新日期列,sql-server,Sql Server,我有一张有10000张唱片的桌子 样品 Id Transaction_Id Contract_Id Contractor_Id ServiceDetail_Id ServiceMonth UnitsDelivered CreateDate -----------------------------------------------------------------------------------------------------------------------

我有一张有10000张唱片的桌子

样品

Id  Transaction_Id  Contract_Id Contractor_Id   ServiceDetail_Id    ServiceMonth    UnitsDelivered  CreateDate
----------------------------------------------------------------------------------------------------------------------------
1   1   352 466 590 2016-03-01  203 2016-04-25 17:01:55.000
2   1   352 466 566 2016-03-01  200 2016-04-25 17:02:38.807
3   1   352 466 138 2016-04-13  20  2016-04-13 00:00:00.000
5   1   352 466 138 2016-04-14  21  2016-04-13 00:00:00.000
6   10011   40  460 68  2016-03-17  10  2016-04-25 17:20:13.413
7   10011   40  460 511 2016-03-17  15  2016-04-25 17:20:13.413
8   10011   40  460 1611    2016-03-17  20  2016-04-25 17:20:13.413
9   20011   352 466 2563    2016-02-05  10  2016-04-25 17:20:25.307
11  100 40  460 68  2016-03-17  10  2016-04-25 17:29:23.653
在这个表中,我有不同日期的
servicemount

我想将
servicemonth
列更新为现有月份的最后日期

  • 假设表中有2016-03-17,则应更新为2016-3-31
  • 假设表中有2016-05-12,则应更新为2016-5-31
有人可以建议一个查询来更新此信息吗

:返回包含指定日期的月份的最后一天,带有可选偏移量

:返回包含指定日期的月份的最后一天,带有可选偏移量

--将getdate()替换为希望其为月底的日期列


--将getdate()替换为您想要的月末日期的日期列

是否可以更新该月第一天的类似值?是否可以更新该月第一天的类似值?
UPDATE ... SET servicemonth = EOMONTH(servicemonth)
Update  servicemonth  
set servicemonth = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))