« CRM Email Router Required to Send Email from Microsoft CRM Web Client | Main | Microsoft Virtual PC 2007 Service Pack 1 is now available »

May 14, 2008

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00e54fb34b6f883300e55224e09c8833

Listed below are links to weblogs that reference Microsoft CRM Reporting by Fiscal Year:

Comments

Michael Dodd

Joel,

Great post. I've worked with similar SQL code myself, and once, when writting a report, I noticed all of the wonderfull SQL Functions that come OOTB for grouping your SQL by DatePart parameters. So I did a little more digging and came up with my own SQL Functions to allow you to group by Quarter:

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--Return The Quarter of a given date
CREATE Function dbo.Fn_BPT_SelectQuarter (
@Date DateTime
)
Returns Int
As
BEGIN
Declare @Result Int
IF DatePart(M, @Date) Between 1 AND 3
Set @Result = 1
IF DatePart(M, @Date) Between 4 AND 6
Set @Result = 2
IF DatePart(M, @Date) Between 7 AND 9
Set @Result = 3
IF DatePart(M, @Date) Between 10 AND 12
Set @Result = 4
Return @Result
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

Other functions can play on this:

--Return The Quarter of a given date
CREATE Function dbo.Fn_BPT_SelectQuarter (
@Date DateTime
)
Returns Int
As
BEGIN
Declare @Result Int
IF DatePart(M, @Date) Between 1 AND 3
Set @Result = 1
IF DatePart(M, @Date) Between 4 AND 6
Set @Result = 2
IF DatePart(M, @Date) Between 7 AND 9
Set @Result = 3
IF DatePart(M, @Date) Between 10 AND 12
Set @Result = 4
Return @Result
END

AND also:

--Return The Next Fiscal Quarter of a given date
ALTER Function dbo.Fn_BPT_NextQuarter (
@Date DateTime
)
Returns Int
As
BEGIN
Declare @Result Int
IF DatePart(M, @Date) Between 1 AND 3
Set @Result = 2
IF DatePart(M, @Date) Between 4 AND 6
Set @Result = 3
IF DatePart(M, @Date) Between 7 AND 9
Set @Result = 4
IF DatePart(M, @Date) Between 10 AND 12
Set @Result = 1
Return @Result
END

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.

Search The Blog

  • Search the Blog
     

    WWW
    this blog

Twitter Updates

    follow me on Twitter