Wednesday, March 21, 2012

quraterly report

I am designing a quarterly report for summary of order received quarterly.
I
need to find out the orderid for the order placed during the quarter, the
order date field is order date.
This report will run in the early morning of first day of the quarter before
any new order is entered.
Can you tell me how to program it?
Thanks,> This report will run in the early morning of first day of the quarter
> before
> any new order is entered.
How are you going to prevent that, set the database to single_user?
Try using a calendar table. Then you can query for data in any quarter,
regardless of whether the quarter ended yesterday or 645 days ago.
http://www.aspfaq.com/2519|||You could use something like this (as example):
USE NORTHWIND
GO
SELECT ORDERID,
CASE DATEPART(Q,ORDERDATE)
WHEN 1 THEN 'QUARTER 1'
WHEN 2 THEN 'QUARTER 2'
WHEN 3 THEN 'QUARTER 3'
ELSE 'QUARTER 4' END AS 'Quarter'
FROM ORDERS
ORDER BY QUARTER
You could also break it out into columns using CASE as well if you prefer.
HTH
Jerry
"qjlee" <qjlee@.discussions.microsoft.com> wrote in message
news:BC95898E-EDA6-40F2-87DB-60E0467EB5FA@.microsoft.com...
>I am designing a quarterly report for summary of order received quarterly.
>I
> need to find out the orderid for the order placed during the quarter, the
> order date field is order date.
> This report will run in the early morning of first day of the quarter
> before
> any new order is entered.
> Can you tell me how to program it?
> Thanks,
>
>|||How could I break into columns by using case?
Thanks,
Li
"Jerry Spivey" wrote:

> You could use something like this (as example):
> USE NORTHWIND
> GO
> SELECT ORDERID,
> CASE DATEPART(Q,ORDERDATE)
> WHEN 1 THEN 'QUARTER 1'
> WHEN 2 THEN 'QUARTER 2'
> WHEN 3 THEN 'QUARTER 3'
> ELSE 'QUARTER 4' END AS 'Quarter'
> FROM ORDERS
> ORDER BY QUARTER
> You could also break it out into columns using CASE as well if you prefer.
> HTH
> Jerry
>
> "qjlee" <qjlee@.discussions.microsoft.com> wrote in message
> news:BC95898E-EDA6-40F2-87DB-60E0467EB5FA@.microsoft.com...
>
>|||qjlee (qjlee@.discussions.microsoft.com) writes:
> How could I break into columns by using case?
SELECT CASE DATEPART(Q,ORDERDATE) WHEN 1 THEN ORDERID ELSE NULL AS Q1,
CASE DATEPART(Q,ORDERDATE) WHEN 2 THEN ORDERID ELSE NULL AS Q2,
CASE DATEPART(Q,ORDERDATE) WHEN 3 THEN ORDERID ELSE NULL AS Q3,
CASE DATEPART(Q,ORDERDATE) WHEN 4 THEN ORDERID ELSE NULL AS Q4
FROM Orders
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.aspsql

No comments:

Post a Comment