下午好,我需要以日历等格式打印一些每日信息,所以我在一些论坛中进行了搜索,包括这个,我得到了一些制作日历的功能和方法,但是当我尝试添加子查询时,崩溃告诉我“不能对包含聚合或子查询的表达式执行聚合函数。”
这是我的代码
;with monthDates
as
(
select DATEADD(month, datediff(month, 0, '2013-09-01'),0) as d
,DATEPART(week, DATEADD(month, datediff(month, 0, '2013-10-30'),0)) as w
union all
select DATEADD(day, 1, d)
,DATEPART(week, DATEADD(day, 1, d))
from monthDates
where d < DATEADD(month, datediff(month, 0, '2013-10-30')+1,-1)
)
select max(case when datepart(dw, d) = 1 then datepart(d,d) else null end) as [Sunday]
,max(case when datepart(dw, d) = 2 then (SELECT Cost FROM Freights WHERE ixMov=16788) else null end) as [Monday]
,max(case when datepart(dw, d) = 3 then datepart(d,d) else null end) as [Tuesday]
,max(case when datepart(dw, d) = 4 then datepart(d,d) else null end) as [Wednesday]
,max(case when datepart(dw, d) = 5 then datepart(d,d) else null end) as [Thursday]
,max(case when datepart(dw, d) = 6 then datepart(d,d) else null end) as [Friday]
,max(case when datepart(dw, d) = 7 then datepart(d,d) else null end) as [Saturday]
from monthDates
group by w
在这种情况下,我只影响星期一,但它向我显示来自 MSSQL 的错误警告
我做错了,也许我不需要使用一些代码来描述我所采取的示例,这些数据是用于我使用 DevExpress 的 XtraReports 的报告,所以我想查询它给我带来了这种格式的信息。
我需要这样的信息....
Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|
NULL |45 |203 |87 |231 |123 |321 |
321 |54 |302 |78 |132 |321 |123 |
154 |44 |283 |47 |131 |128 |NULL |
在没有数据的地方放置 NULL。
谢谢