Cognos Tech Tip: Do you ever wish you had a query with every day?

Learn how to build a Cognos query that returns results for every day so you never miss a date in your time-based reports.

Cognos Queries

Sometimes people want to see every day in a month even if there aren’t records. For instance show me the entire month and the number of marketing transactions that happened per day (even if there weren’t any). If there is no data for a day then you won’t have that day in your results. One way to get around that is to have a query that returns every day and then “outer join” to it to get every day.

Here is a query that returns every day in the current month. You’ll have to tweak it if you need a different set of days but it’s a great start.

select CAST(DATEADD(dd, -number, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))) as date) dt
from master..spt_values
where type = ‘P’ and CAST(DATEADD(dd, -number, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))) as date) >= DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,getdate()),0))

Cheers!

All Posts

Alteryx
Subscribe to our newsletter

Sign up for the very best tutorials and the latest news.

* indicates required

We care about your data in our privacy policy.

Related blog posts

Business Intelligence & Analytics, Cognos BI & Analytics, Cognos Tips & Tricks
The Differences between a Cognos Dashboard and an Active Report
Compare Cognos Dashboards vs Active Reports to understand key differences in capabilities, use cases, and best scenarios for each reporting style.
Business Intelligence & Analytics, Cognos BI & Analytics, Cognos Tips & Tricks, Cognos Training
Auditing for Accurate Cognos Reports
All Cognos reports need to be checked to ensure the report produces accurate data. Follow these tips to eliminate any potential errors in your report.
Cognos BI & Analytics, Cognos Tips & Tricks, Cognos Training
Using IBM Cognos for Microsoft Office
Learn how IBM Cognos for Microsoft Office connects Cognos Analytics data to Excel, Word, and PowerPoint for dynamic, accurate reporting.

Contact Us

Interested in learning more? Contact info@capitalizeconsulting.com.