select SUM(clfbxd.hj) as je from clfbxd where 日期字段 BETWEEN CAST(DATENAME(YEAR,DATEADD(MONTH,-1,GETDATE()))+DATENAME(MONTH,DATEADD(MONTH,-1,GETDATE()))+'25' AS DATE) AND CAST(DATENAME(YEAR,GETDATE())+DATENAME(MONTH,GETDATE())+'25' AS DATE)
写两个函数,一个返回上个月的25号 一个返回本月的25号
between convert(char(7),dateadd(month,-1,getdate()),20)+'-25' and convert(char(7),getdate(),20)+'-25'
WHERE date BETWEEN CAST(CAST(year(getdate())AS VARCHAR)+'-'+CAST(MONTH(dateadd(MONTH,-1,(getdate())))AS VARCHAR)+'-'+'25' AS DATETIME) AND
CAST(CAST(year(getdate())AS VARCHAR)+'-'+CAST(month(getdate())AS VARCHAR)+'-'+'25 23:59:59' AS DATETIME)