Advertisement

07.24.2007 at 06:53AM PDT, ID: 22716959
[x]
Attachment Details

SELECT Statement for DATEPART, DATENAME with different caldendar year

Asked by CyberNerd in SQLBase, SQL Query Syntax

Tags: select, datepart, statement

Hi,
I am running "SELECT" statement to output sales order year nad ordered date by quarterly using following statement:

SET DATEFORMAT mdy
SELECT DATEPART(yy, OrderReceivedDate) AS OrderYear,
             'Q' + DATENAME(qq, OrderReceivedDate) AS OrderQtr

This results in following output:

1/1/2007 thru 3/31/2007 = (OrderQtr = Q1) and (OrderYear = 2007)
4/1/2007 thru  6/30/2007 = (OrderQtr = Q2) and (OrderYear = 2007)
and so on (In accouting term Quarter is broken by "Physical Year").

However, my client's Q1 does not start on Physical Year (1/1/2007) but rather starts on 10/1/2006. So 4 quarter for 2007 is following:

10/1/2006 - 12/31/2006 = Q1 for year 2007
1/1/2007 - 3/31/2007 = Q2 for year 2007
4/1/2007 -  6/30/2007 = Q3 for year 2007
7/1/2007 - 9/30/2007 = Q4 for year 2007

So my question is how can I run select statement using similar to below statement to accomplish above Calendar year which starts on 10/1/yyyy and ends on 9/30/yyyy?

SET DATEFORMAT mdy
SELECT DATEPART(yy, OrderReceivedDate) AS OrderYear,
             'Q' + DATENAME(qq, OrderReceivedDate) AS OrderQtr

Thank you in advance,

CNStart Free Trial
 
Loading Advertisement...
 
[+][-]07.24.2007 at 07:10AM PDT, ID: 19556246

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2007 at 07:11AM PDT, ID: 19556249

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2007 at 08:06AM PDT, ID: 19556797

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.26.2007 at 03:08PM PDT, ID: 19578757

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQLBase, SQL Query Syntax
Tags: select, datepart, statement
Sign Up Now!
Solution Provided By: kaosyeti
Participating Experts: 1
Solution Grade: B
 
 
[+][-]05.09.2008 at 07:06AM PDT, ID: 21532921

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32