DataTable中的日期问题 [英] Date Problem in DataTable
问题描述
伙计,
我处于极度困境中
我在过去7个月内根据给定日期从数据库中获取销售详情。
例如..
如果我今天给出日期。 2014年2月24日,如果数据库中有数据
,查询将返回数据表中的数据,如下所示。
Guys,
I am in great dilemma
I am fetching last 7 months Sales details from the database based on given date.
For example..
if i am giving todays date. 24/02/2014, if data is there in the DB
the query will returns the data in the datatable like this.
Year Month Sales Cancel
2013 Aug 100 23
2013 Sep 50 23
2013 Oct 70 23
2013 Nov 90 23
2013 Dec 60 23
2014 Jan 900 23
2014 Feb 100 23
我的问题是。如果数据库表只包含数据表中的单行
年月销售取消
即2013年12月20日12.
我必须显示另一个月的销售和取消为零如下所示
My problem is that. if the database table contains only Single row in the datatable
Year Month Sales Cancel
ie, 2013 Dec 20 12.
I have to Show the other Month Sales and Cancel as Zero Like below
Year Month Sales Cancel
2013 Aug 0 0
2013 Sep 0 0
2013 Oct 0 0
2013 Nov 0 0
2013 Dec 20 12
2014 Jan 0 0
2014 Feb 0 0
我被困了。
请帮助我。
在此先感谢
Saju
I am Stuck up.
Please help me.
Thanks in Advance
Saju
推荐答案
尝试使用此查询。
Hi,
Try using this query.
SELECT DATEPART(MONTH,DATEADD(mm,-Number+1,GETDATE()))
FROM Master.dbo.spt_Values
WHERE Name IS NULL AND Number BETWEEN DATEPART(MONTH,getdate()) AND DATEPART(MONTH,getdate()) + 5
ORDER BY -Number
这篇关于DataTable中的日期问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!