SSRS - 按日期表达式分组
使用 SS 报告服务 2008,我正在考虑设置按日期分组的月份销售数据的默认报告。
从理论上讲,它应该看起来有点像:
Date Total Sales Qty
----------------------------------
01/04/2011 $15.00 3
02/04/2011 $20.00 4
03/04/2011 $00.00 0
Etc
我遇到的问题是一个月中没有记录的日子被跳过。 (如上面的 03/04/2011 所示)。有没有办法显示没有记录的日期?
Using SS reporting service 2008, I'm looking at setting up a default report on sale figures through the month grouping by date.
In theory it should look a little like:
Date Total Sales Qty
----------------------------------
01/04/2011 $15.00 3
02/04/2011 $20.00 4
03/04/2011 $00.00 0
Etc
Problem I'm having is the days of the month that have no records are being skipped. (Like 03/04/2011 above). Is there a way to show the dates that have no records?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 SSRS 中没有办法专门执行此操作,但可以在 SQL 查询中完成。
您需要生成一个临时表(如果您要经常执行此操作,则数据库中的永久表也可能很好),其中包含顺序日期列表,然后使用外部将其连接到现有数据查询中加入。这样,没有数据的日期在连接后将在表中显示为空条目。
例如,如果您有以下表
DateList
SalesData
,那么您可以使用以下查询来获取销售数据:
没有销售记录的日期为空记录。
请参阅此问题了解有关生成要加入的日期列表的信息。
There is no way to specifically do this in SSRS, but it can be accomplished in the SQL query.
You need to generate a temporary table (a permanent table in the database could also be good, if you are going to be doing this alot) with a list of sequential dates in it, and then join this onto the existing data query with an outer join. This way dates with no data will appear as null entries in the table after the join.
For example, if you had the following tables
DateList
SalesData
then you could use the following query to get the sales data with the
null records for days where there are no sales recorded.
See this question for information on generating a list of dates to join on.
为了扩展 Nathan 的答案,为了避免 null,您的 select 语句可以在 sd.QTY 字段上使用 isnull:
isnull(sd.QTY,0) as '数量'
To expand on Nathan's answer, to avoid nulls your select statement could use isnull on the sd.QTY field:
isnull(sd.QTY,0) as 'Qty'