May 22, 2008 at 3:25 am
Hi,
I want to display the weeks for a particular month.
i.e., i will pass @year=2008 and @month=5
i want output like Week1, week2, week3, week4, week5 like that.
Example:
1st query:
select month, count(*) from
sample data:
month Count
---------------------
1 45
2 64
3 19
4 27
5 98
I need the 2 nd query:
from the above query i will pass the month number, and i need output like the below:
Sample::::
week Count
-------------------
week1 10
week2 20
week3 40
week4 28
If any one knows the solution for the above query, please help me.
Thanks in Advance.
Regards
Venki
May 22, 2008 at 2:20 pm
I'm not sure I fully understand your problem. Can you post DDL for your table and the sample data you would expect to generate the results you've already posted?
May 22, 2008 at 4:10 pm
You need to define what a "week" is before anyone can help... Do weeks start on a Monday or ??? Are you talking about ISO week #'s or SQL Server Week numbers?
--Jeff Moden
May 22, 2008 at 5:07 pm
To add to the list of questions:
..are we talking full weeks (fully circumscribed within the month)? weeks that START within a month/weeks that END within a month?
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
May 23, 2008 at 3:50 am
Hi,
In my requirement week starts with monday and ends with sunday.
I will pass year for ex:2008
and month =May
expected result:
weeks count
---------------
week1 4
week2 90
week3 8
etc..
corresponding month weeks only
DatePart function will returns weeks from 1 to 53.
Can u please help me.
May 24, 2008 at 9:04 am
Alright, Venki... you've given us just about nothing to go on... no table Create statement, no data, no column names... and your sample query of...
1st query:
select month, count(*) from
sample data:
month Count
---------------------
1 45
2 64
3 19
4 27
5 98
... really doesn't tell us anything about the table you have. Do you actually have a table with a "Month" column in it? Does it have a "Year" column in it? If so, what is their datatype? Or, do you have a column of the DATETIME datatype?
Because you've not adequately defined the problem, you're not getting the help you need or want because folks just don't want to guess about your requirements nor do they want to take the time to setup some test data to ensure that their answer will actually work for you.
So, what you need to do is you need to read and follow the URL in my signature. Make the sample data "self loading" like in the article. If the data is larger than 20 or 30 rows, attach it as a file in the format like in the article.
This is not a difficult problem, but you haven't given us enough info so solve it correctly.
--Jeff Moden
May 27, 2008 at 9:05 am
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply