【发布时间】:2018-05-17 14:56:47
【问题描述】:
我有一份在 Cognos 上运行的报告,我们正在迁移到 SSRS。 Cognos SQL 使用rank 函数。有人可以帮我弄清楚如何在 T-SQL 中编写相同的查询:
rank() over (at "left"(upper(cast_char(TIMESTAMP '2018-04-30 00:00:00.0')), 3), dim_customer.concern_name
order by XSUM(case when (cast(dim_order_date.order_date_date as date) between
CAST(:PQ2 AS timestamp) and CAST(:PQ1 AS timestamp))
then invoice_lines_fact3.fare_taken else 0 end
at "left"(upper(cast_char(TIMESTAMP '2018-04-30 00:00:00.0')),3),dim_customer.concern_name,invoice_lines_fact3.inv_line_id
for "left"(upper(cast_char(TIMESTAMP '2018-04-30 00:00:00.0')),3),dim_customer.concern_name ) desc nulls last) as Rank1,`
还有这个where子句过滤器:
((cast(dim_order_date.order_date_date as date) between _add_years(cast(TIMESTAMP '2018-04-01 00:00:00.0' as date),(-1)) and CAST(:PQ1 AS timestamp))
and (((dim_route.AIRLCD in ('CC','AA')) and (dim_route.END_DATE < CAST(:PQ2 AS timestamp)))
or (dim_route.END_DATE is NULL)))
【问题讨论】:
-
在 Cognos Report Studio 中查看生成的 SQL 时,可以将其从 Cognos SQL 切换到 Native SQL。你试过这个吗?
-
您将无法轻松地将其用于 Sql Server 2008 R2。
Rank()函数仅在 Sql Server 2012 及更高版本中可用。此外,Sql Server 2008 R2 距离生命周期结束还有不到 14 个月的时间(2019 年 7 月 9 日)。在那之后,它将不再获得任何更新,甚至没有关键的安全补丁。现在也该开始您的 Sql Server 升级项目了。 -
我知道我将无法轻松地为 SQL Server 2008 R2 调整此查询,但我仍然需要对其进行转换以便任何人都可以帮助我解决这个问题吗?谢谢
标签: tsql sql-server-2008-r2 ssrs-2008-r2 cognos-8