简体   繁体   中英

Migrate report from COGNOS to SQL Server

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM