Author |
Topic  |
|
indianhunk
Starting Member
7 Posts |
Posted - 12/09/2012 : 04:21:23
|
Dear friends, I am having a problem in sql server2000. In my database i have columns like service_id, date, year etc. I have to retreive data of sm services per monthwise e.g. january2010. Please help me how i can retreive it??
|
|
sunitabeck
Flowing Fount of Yak Knowledge
5155 Posts |
Posted - 12/09/2012 : 08:19:37
|
Hard to say what your query should be without seeing the structure of your tables and some sample data. This article may help you post sufficient information for someone to be able to help you.
In the absence of that, based on what I understood from your posting, you may need to do something like this:SELECT
DATEADD(mm,DATEDIFF(mm,0,[datecolumn]),0) AS YearAndMonth,
COUNT(*) AS RecordsPerMonth
FROM
YourTable
GROUP BY
DATEADD(mm,DATEDIFF(mm,0,[datecolumn]),0) That will count the number of rows in the table and list them grouped by month. |
 |
|
indianhunk
Starting Member
7 Posts |
Posted - 12/09/2012 : 12:27:41
|
quote: Originally posted by sunitabeck
Hard to say what your query should be without seeing the structure of your tables and some sample data. This article may help you post sufficient information for someone to be able to help you.
In the absence of that, based on what I understood from your posting, you may need to do something like this:SELECT
DATEADD(mm,DATEDIFF(mm,0,[datecolumn]),0) AS YearAndMonth,
COUNT(*) AS RecordsPerMonth
FROM
YourTable
GROUP BY
DATEADD(mm,DATEDIFF(mm,0,[datecolumn]),0) That will count the number of rows in the table and list them grouped by month.
Thank you.. Thank you.. Thank you.. I tried the query you told on my old backup and it worked. will use this query on actual db tomorrow.. Thanks alot again. :) |
 |
|
indianhunk
Starting Member
7 Posts |
Posted - 12/13/2012 : 03:47:57
|
quote: Originally posted by indianhunk
quote: Originally posted by sunitabeck
Hard to say what your query should be without seeing the structure of your tables and some sample data. This article may help you post sufficient information for someone to be able to help you.
In the absence of that, based on what I understood from your posting, you may need to do something like this:SELECT
DATEADD(mm,DATEDIFF(mm,0,[datecolumn]),0) AS YearAndMonth,
COUNT(*) AS RecordsPerMonth
FROM
YourTable
GROUP BY
DATEADD(mm,DATEDIFF(mm,0,[datecolumn]),0) That will count the number of rows in the table and list them grouped by month.
Thank you.. Thank you.. Thank you.. I tried the query you told on my old backup and it worked. will use this query on actual db tomorrow.. Thanks alot again. :)
Thank you.. I have done that.. very useful query for me.. Thank you again. |
 |
|
sunitabeck
Flowing Fount of Yak Knowledge
5155 Posts |
Posted - 12/13/2012 : 08:10:50
|
You are very welcome, IH! |
 |
|
|
Topic  |
|
|
|