sql 修改日期字段的格式

废话不多说,直接上sql:

UPDATE db_huanjing_GM_YanQing_TEST.dbo.GM_AY_yiqi_copy
SET jiandingriqi = concat (
 Datepart(
  yyyy,
  CAST (
   jiandingriqi AS datetime
  )
 ),
 IIF (
  Datepart(
   mm,
   CAST (
    jiandingriqi AS datetime
   )
  ) > 9,
  concat (
   '年',
   Datepart(
    mm,
    CAST (
     jiandingriqi AS datetime
    )
   )
  ),
  concat (
   '年0',
   Datepart(
    mm,
    CAST (
     jiandingriqi AS datetime
    )
   )
  )
 ),
 IIF (
  Datepart(
   dd,
   CAST (
    jiandingriqi AS datetime
   )
  ) > 9,
  concat (
   '月',
   Datepart(
    dd,
    CAST (
     jiandingriqi AS datetime
    )
   )
  ),
  concat (
   '月0',
   Datepart(
    dd,
    CAST (
     jiandingriqi AS datetime
    )
   )
  )
 ),
 '日'
) where jiandingriqi != '';

 

    原文作者:houzhanwublog
    原文地址: https://blog.csdn.net/qq_27404929/article/details/103779287
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞