SQL
sql常用值转换
将"2022-09"字符串得到2022:
DATENAME(YEAR,Cast(YearMonth+'-01' As DateTime))
将datetime得到2022-09-22:
convert(varchar(10),CreatedDate,120)
UTC:GETUTCDATE()
UTC转LOCAL:CONVERT(datetime, SWITCHOFFSET(CONVERT(DATETIMEOFFSET, GETUTCDATE()), DATENAME(TZOFFSET, SYSDATETIMEOFFSET())))
修改字段长度:ALTER TABLE table ALTER COLUMN test NVARCHAR(50)