Migrate report from COGNOS to SQL Server

混江龙づ霸主 提交于 2020-08-06 03:45:40

问题


I have the following query generated in a Cognos report.

My problem is I need it to work, with the same logic / filter in SQL Server. Can the filter below (COGNOS syntax) be generated to work in the same way, like a WHERE in SQL Server?

select
      *    
from
       dbo.ia_code 
group by
       client__iacode.ia_code,
       client__iacode.ia_short_descr
 ------ here my problem
filter
       (rank() over ( at client__iacode.ia_code order by XCOUNT(client.client_code  at client__iacode.ia_code,client.client_id  for client__iacode.ia_code ) desc nulls last) <= 25) and
       (RCOUNT(rank() over ( at client__iacode.ia_code order by XCOUNT(client_document.client_document_id  for client__iacode.ia_code ) desc nulls last)  at client__iacode.ia_code  order by rank() over ( at client__iacode.ia_code order by XCOUNT(client_document.client_document_id  for client__iacode.ia_code ) desc nulls last) asc,client__iacode.ia_code asc,client__iacode.ia_short_descr asc ) <= 25)

Any help would be appreciated.


回答1:


  1. Use where before group by for filter
  2. Group by just use for aggregate-function call in query like below
select
      Sum(id),client__iacode.ia_code,client__iacode.ia_short_descr
from
       dbo.ia_code 
group by
       client__iacode.ia_code,
       client__iacode.ia_short_descr
  1. Use having for functionality filter in query

Read this statement for how to use :

  1. Where : w3schools
  2. Group by: w3shoolcs
  3. Having : w3shoolcs

in finally : I tried change your code to sql server but i don't now about out put of this code. please add table sample data and sample of out put.




回答2:


First try changing the query's (or data source's) "Rollup Processing" property to "Database". That should help converting extended aggregate functions (XCOUNT etc) to native SQL. Also check out "Use SQL parameters" property and set it to "Literal" and see if that will helps with the parameters in native SQL. Once you do those, paste the new generated native query here.

Screenshot of the properties window

This is a snippet from my answer to the following Stackoverflow question. Read more details there and also follow that question as it may help with your question too.

Convert IBM Cognos SQL which contains a filter to Microsoft SQL Server Query



来源:https://stackoverflow.com/questions/63017542/migrate-report-from-cognos-to-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!