Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Quarterly trending
I have a reporting query that I need to do a quarterly trending on.  A
user enters a begining date and end date, and from there, I have to
determine the closest quarter to it.

Also, the actual Quarter starts on Sept 4th, then add 13 weeks to that,
will be the second quarter.

I was able to do the trending for week/month/year, but I'm stuck on
this quarterly trending.

Any help would be greatly appreciated.

Example of the monthly trending that I have written:

SELECT & #91;VALUE],DATEPART(
MONTH,DATESAMPLE) AS[MONTH]
FROM #TABLE
GROUP BY [VALUE],  DATEPART(MONTH,DATES
AMPLE)
ORDER BY EDIT_SP,  DATEPART(MONTH,DATES
AMPLE)


Report this thread to moderator Post Follow-up to this message
Old Post
tran.loan@gmail.com
10-27-05 02:25 PM


Re: Quarterly trending
This would be easy if your business used calendar quarters instead;
can't you make them change? <G>  You could then group by
DATEPART(Quarter, DateSample)

Since that's not likely, a solution might be to use a calendar table
that takes a key Date and maps it to the appropriate quarter, eg:

CREATE TABLE Calendar (DateKey smalldatetime, PeriodQuarter int....
(other columns))

INSERT INTO Calendar (DateKey, PeriodQuarter)
SELECT '9/1/2005', 2
UNION ALL
SELECT '9/4/2005', 3

etc

You could then join and group on the PeriodQuarter value.

Just an idea.
Stu


Report this thread to moderator Post Follow-up to this message
Old Post
Stu
10-27-05 02:25 PM


Re: Quarterly trending
create a table of the quarters:

CREATE TABLE Quarters
(quarter_name  CHAR(20) NOT NULL PRIMARY KEY,
start_date  DATETIME NOT NULL,
end_date DATETIME NOT NULL,
CHECK (start_date < end_date ));
 

Whatr does thst mean?  give me an algorithm.


Report this thread to moderator Post Follow-up to this message
Old Post
--CELKO--
10-27-05 02:25 PM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 03:16 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006