Business Intelligence Blogs

View blogs by industry experts on topics such as SSAS, SSIS, SSRS, Power BI, Performance Tuning, Azure, Big Data and much more! You can also sign up to post your own business intelligence blog.

«October 2015»

Data Warehouse from the Ground Up at SQL Saturday Orlando, FL on Oct. 10th

SQL Saturday #442SQL Saturday #442 is upon us and yours truly will be presenting in Orlando, Florida on October 10th alongside Mitchell Pearson (b|t). The session is scheduled at 10:35 AM and will last until 11:35 AM. I’m very excited to be presenting at SQL Saturday Orlando this year as it’ll be my first presenting this session in person and my first time speaking at SQL Saturday Orlando! If you haven’t registered yet for this event, you need to do that. This event will be top notch!

My session is called Designing a Data Warehouse from the Ground Up. What if you could approach any business process in your organization and quickly design an effective and optimal dimensional model using a standardized step-by-step method? In this session I’ll discuss the steps required to design a unified dimensional model that is optimized for reporting and follows widely accepted best practices. We’ll also discuss how the design of our dimensional model affects a SQL Server Analysis Services solution and how the choices we make during the data warehouse design phase can make or break our SSAS cubes. You may remember that I did this session a while back for Pragmatic Works via webinar. I’ll be doing the same session at SQL Saturday Orlando but on-prem! ;)

So get signed up for this event now! It’s only 11 days away!

Read more

Create Date Dimension with Fiscal and Time

Here are three scripts that create and Date and Time Dimension and can add the fiscal columns too. First run the Dim Date script first to create the DimDate table. Make sure you change the start date and end date on the script to your preference. Then run the add Fiscal Dates scripts to add the fiscal columns. Make sure you alter the Fiscal script to set the date offset amount. The comments in the script will help you with this.

This zip file contains three SQL scripts.

Create Dim Date

Create Dim Time

Add Fiscal Dates

These will create a Date Dimension table and allow you to run the add fiscal script to add the fiscal columns if you desire. The Create Dim Time will create a time dimension with every second of the day for those that need actual time analysis of your data.

Make sure you set the start date and end date in the create dim date script. Set the dateoffset in the fiscal script.

Download the script here:


Read more

SQLBIGeek’s Function Friday - Return First Day of Quarter

  • 24 October 2010
  • Author: briankmcdonald
  • Number of views: 5647


Brian K. McDonald, MCDBA, MCSD 

Brian K. McDonald


Twitter: @briankmcdonald



Welcome to the first of my “SQLBIGeek’s Function Friday” blog series. I understand that I am posting it on Sunday for this first post, rather than Friday. However, going forward I am going to post a new function each Friday. Whether it be cleaning up an old function that I have come across (written by others or myself J) or it is just something that I have written lately. Either way, I hope that you enjoy the series and that you can get some useful ideas or functions to use in your environment.



I recently came across a function that returned the first day of the quarter based on a date value supplied. At first glance, it appeared to be a little longer than it needed to be. I could definitely see where they were going with it and why they did it that way, but I thought that I might be able to shrink it down a little bit with less typing (minus the commenting of course). Script 1 below shows us this function.


Script 1: Original Function

CREATE FUNCTION [dbo].[ufn_GetTheFirstDayOfTheQuarter]


      @InDate DATETIME






    SET @OutDate =

            CAST(YEAR(@InDate) AS VARCHAR(4)) +


                WHEN MONTH(@InDate) IN (1,2,3) THEN '/01/01'

                WHEN MONTH(@InDate) IN (4,5,6) THEN '/04/01'

                WHEN MONTH(@InDate) IN (7,8,9) THEN '/07/01'

                WHEN MONTH(@InDate) IN (10,11,12) THEN '/10/01'



    RETURN @OutDate




--Execute it a few times

SELECT dbo.ufn_GetTheFirstDayOfTheQuarter ('3/21/2010')

SELECT dbo.ufn_GetTheFirstDayOfTheQuarter ('6/21/2010')

SELECT dbo.ufn_GetTheFirstDayOfTheQuarter ('9/21/2010')

SELECT dbo.ufn_GetTheFirstDayOfTheQuarter ('12/21/2010')


--Clean up my function

DROP FUNCTION dbo.ufn_GetTheFirstDayOfTheQuarter


I went home that night and looked at the query again and thought for a minute… then I started typing. The results are shown in script 2 and 3 below. Using the DATEDIFF and DATEADD functions, I was able to determine the first day of the quarter in one line without a case statement.

Script 2 was a quick test query that I came up with.


Script 2: Determine First Date in Quarter Select Statement

DECLARE @pInputDate SMALLDATETIME = '9/21/2010'

SELECT DATEPART(Quarter,@pInputDate) AS Quarter

      , DATEADD(qq, DATEDIFF(qq,0,@pInputDate), 0) AS FirstDayOfQuarter 


So using my slightly simplified select script above and incorporating it into a function would look something like that shown in script 3.


Script 3: Determine First Date in Quarter Function

CREATE FUNCTION [dbo].[BKM_ufn_GetTheFirstDayOfTheQuarter]


      @InDate    DATETIME


Created By:       Brian K. McDonald, MCDBA, MCSD (


Twitter:          @briankmcdonald

Date:             10/24/2010

Purpose:          Return the first day of the quarter based on date

                  passed into the function


Usage:            SELECT dbo.BKM_ufn_GetTheFirstDayOfTheQuarter ('3/21/2010')


Modification History









SET @OutDate = DATEADD(qq, DATEDIFF(qq,0,@InDate), 0)


      RETURN @OutDate




--Execute it a few times

SELECT dbo.BKM_ufn_GetTheFirstDayOfTheQuarter ('3/21/2010')

SELECT dbo.BKM_ufn_GetTheFirstDayOfTheQuarter ('6/21/2010')

SELECT dbo.BKM_ufn_GetTheFirstDayOfTheQuarter ('9/21/2010')

SELECT dbo.BKM_ufn_GetTheFirstDayOfTheQuarter ('12/21/2010')


--Clean up my function

DROP FUNCTION dbo.BKM_ufn_GetTheFirstDayOfTheQuarter 


I understand that sometimes it takes more typing to make queries perform better, but in this case the query plan is exactly the same. Figure 1 shows the execution plan of executing each of the functions for 3/21/2010.


Figure 1: Execution Plan

 Execution Plan - Brian K. McDonald


** Note: This is not the only way that one could determine the first date of the quarter, but IMHO is the easiest to understand and quite a bit less typing J **


Please be sure to return for the next BISQLGeek's Function Friday, as I will show you how to parse through some crazy integer values that are representative of duration. I hope that you have enjoyed this post. If you did, please take just a moment to rate it below! Also, if you don’t already, please be sure to follow me on twitter at @briankmcdonald. Also note that you can subscribe to an RSS feed of my blogs.



Brian K. McDonald, MCDBA, MCSD
Business Intelligence Consultant – Pragmatic Works

Email: | Blogs: SQLBIGeek | SQLServerCentral | BIDN

Twitter: @briankmcdonald | LinkedIn:

Categories: Blogs
Rate this article:
No rating


Other posts by briankmcdonald

Please login or register to post comments.