【问题标题】:how to convert a query from cognos sql to t-sql如何将查询从 cognos sql 转换为 t-sql
【发布时间】: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


【解决方案1】:

你 rank() 函数在 2008 年可用。

查看您的代码后,您有一个“XSUM”命令。

解决这个问题应该是您的首要任务。以下是解决方案的链接(堆栈上)。

Converting Cognos reports to SSRS , what does XSUM command does?

修复此问题后,您的排名功能可能会正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-04
    • 1970-01-01
    • 2017-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多