bhargav kommineni
bhargav kommineni

Reputation: 11

How to write a SQL query in Cognos Report Studio to show the values in for a range

I have a column days, which will have the days from 1,2,3,...........365,433,892,1200,1600 ...

I want to write a query to show the days range .. 0-30 31-60 61-90 91-180 181-365 1-2 years

2years All

Can anyone please help me on his

Upvotes: 1

Views: 4085

Answers (1)

ivanatpr
ivanatpr

Reputation: 1880

You can hardcode it in the report logic ( case when days between 0 and 30 then days_range = '0-30' when days between 31 and 60 then ...) but the better solution would be to set up a reference table that stores your ranges and their label. Something like a table with the columns RANGE_LABEL, RANGE_FROM, RANGE_THROUGH and then do something like

select base_query.*, Range_Types.RANGE_LABEL
from base_query 
join Range_Types on base_query.days between RANGE_FROM and RANGE_THROUGH

Upvotes: 1

Related Questions