Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Selecting Quarter and Year Parameter

 
   Database Forums (Home) -> MSEQ RSS
Next:  SQL2005 --> Excel 2007 via SSIS (and sproc) an..  
Author Message
Ryan Mcbee

External


Since: May 17, 2007
Posts: 9



(Msg. 1) Posted: Fri Dec 07, 2007 6:37 am
Post subject: Selecting Quarter and Year Parameter
Archived from groups: microsoft>public>sqlserver>mseq (more info?)

I am working on a report where the end user would like to say giving me data
for quarter 1 of 2007,ect. The data in my table has the year and date fields.

How do I begin to start this query? I know I can say @Year for the year
parameter, but I am not sure how to get it to return a particular quarters
worth of data.

Any help is appreciated.
Thanks,
Ryan

 >> Stay informed about: Selecting Quarter and Year Parameter 
Back to top
Login to vote
Hugo Kornelis

External


Since: Jan 31, 2006
Posts: 335



(Msg. 2) Posted: Fri Dec 07, 2007 7:58 pm
Post subject: Re: Selecting Quarter and Year Parameter [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Fri, 7 Dec 2007 06:37:00 -0800, Ryan Mcbee wrote:

>I am working on a report where the end user would like to say giving me data
>for quarter 1 of 2007,ect. The data in my table has the year and date fields.

Hi Ryan,

Huh? Year AND date fields? Isn't that a bit redundant, since the year is
part of the date? Try to see if there is any good reason for this
duplication, otherwise get rid of the Year column.

>How do I begin to start this query? I know I can say @Year for the year
>parameter, but I am not sure how to get it to return a particular quarters
>worth of data.

DECLARE @Year int,
@Quarter tinyint;
SET @Year = 2007;
SET @Quarter = 1;

DECLARE @StartRange datetime,
@EndRange datetime;
SET @StartRange = DATEADD(year,
@Year - 2000,
DATEADD(quarter, @Quarter - 1, '20000101'));
SET @EndRange = DATEADD(quarter, 1, @StartRange);

SELECT ...
FROM ...
WHERE YourDate >= @StartRange
AND YourDate M @EndRange;

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

 >> Stay informed about: Selecting Quarter and Year Parameter 
Back to top
Login to vote
Ryan Mcbee

External


Since: May 17, 2007
Posts: 9



(Msg. 3) Posted: Fri Dec 07, 2007 7:58 pm
Post subject: Re: Selecting Quarter and Year Parameter [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks, this should give a good start. Unfortunately, I am building a report
off of another Microsoft application, Great Plains.

Ryan

"Hugo Kornelis" wrote:

> On Fri, 7 Dec 2007 06:37:00 -0800, Ryan Mcbee wrote:
>
> >I am working on a report where the end user would like to say giving me data
> >for quarter 1 of 2007,ect. The data in my table has the year and date fields.
>
> Hi Ryan,
>
> Huh? Year AND date fields? Isn't that a bit redundant, since the year is
> part of the date? Try to see if there is any good reason for this
> duplication, otherwise get rid of the Year column.
>
> >How do I begin to start this query? I know I can say @Year for the year
> >parameter, but I am not sure how to get it to return a particular quarters
> >worth of data.
>
> DECLARE @Year int,
> @Quarter tinyint;
> SET @Year = 2007;
> SET @Quarter = 1;
>
> DECLARE @StartRange datetime,
> @EndRange datetime;
> SET @StartRange = DATEADD(year,
> @Year - 2000,
> DATEADD(quarter, @Quarter - 1, '20000101'));
> SET @EndRange = DATEADD(quarter, 1, @StartRange);
>
> SELECT ...
> FROM ...
> WHERE YourDate >= @StartRange
> AND YourDate M @EndRange;
>
> --
> Hugo Kornelis, SQL Server MVP
> My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
>
 >> Stay informed about: Selecting Quarter and Year Parameter 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Selecting by date - I have a table that has the significant date set up as a CHAR datatype with length of 8, i.e 20051027. I want to select all transactions where this date equals the system date. -- Stan Gosselin

selecting colunm with a space '' - When I submit a sql : select * from view from column='' the view is pointing to oracle table with ole db provider for oracle In mssql2000, the result return rows which containing a space ' ' However, in mssql2005, the result return no rows . Any..

Selecting random rows from a dataset - Question: If I have created a select statement that returns all possible values, can I step through this list using SQL to get a random selection of 10% of the rows? If so, what commands should I be looking at? The closest I've came was to get the....

Selecting data from one table based on conditions in anoth.. - I'm used to doing simple queries from individual tables, so I hope someone can help with this. I need to select unique data from a column in table1 based on the value of a column in table2. The data in the column of table1 is not all unique, so I ..

adding a query as parameter using 'contains' logic - Hello, Setting parameter ranges for a query is very useful. How can I specify : begins with ...... and make that a parameter (in this case first 5 digits of a project name)? Liek '%[parameter3]%' does not work. What should it be? Help much..
   Database Forums (Home) -> MSEQ All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]