前言:
目前你们对“sqlserver获取上个月最后一天”大体比较珍视,大家都需要学习一些“sqlserver获取上个月最后一天”的相关资讯。那么小编在网摘上收集了一些有关“sqlserver获取上个月最后一天””的相关知识,希望小伙伴们能喜欢,同学们快快来学习一下吧!获取当月天数
SELECT DATEPART(MM,GETDATE()) AS '月',32 - DAY(GETDATE() + 32 - DAY(GETDATE())) AS '天数'获取上个月天数
SELECT DATEPART(MM,GETDATE()) -1 AS '月',DAY(GETDATE() - DAY(GETDATE())) AS '天数'获取当月剩余多少天
SELECT DATEPART(MM,GETDATE()) AS '月', (32 - DAY(GETDATE() + 32 - DAY(GETDATE()))) - DAY(GETDATE()) AS '剩余天数'获取指定月份的天数
DECLARE @FMONTH VARCHAR(6)SET @FMONTH = '202304'SELECT @FMONTH AS '年月', DAY(DATEADD(MONTH,1,@FMONTH+'01') - 1) AS '天数'
统计本周的销量数据
SELECT CAST(SUM(t1.FQTY) AS DECIMAL(18,2)) AS '本周'FROM T_SAL_ORDER t0INNER JOIN T_SAL_ORDERENTRY t1 ON t0.FID = t1.FIDWHERE DATEDIFF(WEEK,t0.FDATE, GETDATE()) = 0统计本月的销量数据
SELECT CAST(SUM(t1.FQTY) AS DECIMAL(18,2)) AS '本月'FROM T_SAL_ORDER t0INNER JOIN T_SAL_ORDERENTRY t1 ON t0.FID = t1.FIDWHERE DATEDIFF(MONTH,t0.FDATE, GETDATE()) = 0统计上月的销量数据
SELECT CAST(SUM(t1.FQTY) AS DECIMAL(18,2)) AS '上月'FROM T_SAL_ORDER t0INNER JOIN T_SAL_ORDERENTRY t1 ON t0.FID = t1.FIDWHERE DATEDIFF(MONTH,t0.FDATE, GETDATE()) = 1统计本年的销量数据
SELECT CAST(SUM(t1.FQTY) AS DECIMAL(18,2)) AS '本年'FROM T_SAL_ORDER t0INNER JOIN T_SAL_ORDERENTRY t1 ON t0.FID = t1.FIDWHERE DATEDIFF(YEAR,t0.FDATE, GETDATE()) = 0统计本季度销量数据
SELECT CAST(SUM(t1.FQTY) AS DECIMAL(18,2)) AS '本季度'FROM T_SAL_ORDER t0INNER JOIN T_SAL_ORDERENTRY t1 ON t0.FID = t1.FIDWHERE DATEPART(QQ,t0.FDATE) = DATEPART (QQ, GETDATE()) AND DATEPART(YY,t0.FDATE) = DATEPART(YY, GETDATE())
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #sqlserver获取上个月最后一天