获取当前年度的记录-1 [英] Get records from currentyear - 1

查看:111
本文介绍了获取当前年度的记录-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

我正在做一些有关销售数字的报告,并希望做出一些常规报告,这些报告会随着时间的流逝而更新.这意味着我希望获得当年的所有销售额,并希望在另一份报告中获得当年的-1和NeXT的-2.这可能吗?

现在,我正在使用以下方法获取当前年份-但如何获取-1和-2等等..


= YEAR(GETDATE()))

我完整的SQL查询

Hello freinds

I am doing some reporting on sales figures and would like to make some generic reports that will update as time goes by. This Means that I would like to get all sales from current year and in another report current year -1 and in the NeXT year -2.. Is this possible?

Right now i''m using the below to get the current year - but how to get -1 and -2 and so on..


= YEAR(GETDATE()))

My full SQL Query

SELECT CAST(SUM(Cust.[Sales (LCY)]) AS decimal(8 , 2)) AS Totalsales, Cust.[Customer No.], Customer.Name 
FROM [Cust. Ledger Entry] AS Cust INNER JOIN Customer ON Cust.[Customer No.] = Customer.[No.] 
WHERE (Cust.[Document Type] = 2) AND (YEAR(Cust.[Posting Date]) = YEAR(GETDATE())) 
GROUP BY Cust.[Customer No.], Customer.Name ORDER BY Totalsales DESC

推荐答案

使用DateAdd函数.
MSDN上的日期添加
[ ^ ]

Use the DateAdd function.
DateAdd on MSDN
[^]

@LastYear = DateAdd(yyyy, -1, GetDate())
@TwoYearsAgo = DateAdd(yyyy, -2, GetDate())


只需使用YEAR(GetDate() )-任意2或-1.
Just use YEAR(GetDate()) - 2 or -1 of whatever you want.


这篇关于获取当前年度的记录-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆