--上个月1号如 2024-10-01 00:00:00.000
select DATEADD(month, DATEDIFF(month, 0, GETDATE())-1, 0);
-下个月1号如2024-12-01 00:00:00.000
select DATEADD(month, DATEDIFF(month, 0, GETDATE())+1, 0);
--返回2024-11的格式
select YearMonth
from Dec_EPInventoryGnameCount;
-- 转化为2024-11-01 00:00:00.000
select CONVERT(DATETIME, YearMonth + '-01')
from Dec_EPInventoryGnameCount;
/*
-- 删除最近2个月的数据
DELETE FROM Dec_EPInventoryGnameCount where
CONVERT(DATETIME, YearMonth + '-01') >= DATEADD(month, DATEDIFF(month, 0, GETDATE())-1, 0)
and CONVERT(DATETIME, YearMonth + '-01') < DATEADD(month, DATEDIFF(month, 0, GETDATE())+1, 0)
*/