问题
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 - 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
- Use having for functionality filter in query
Read this statement for how to use :
- Where : w3schools
- Group by: w3shoolcs
- 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