Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 dont know how to retrieve it

Author  Topic 

indianhunk
Starting Member

7 Posts

Posted - 2012-12-09 : 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
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-12-09 : 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.
Go to Top of Page

indianhunk
Starting Member

7 Posts

Posted - 2012-12-09 : 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. :)
Go to Top of Page

indianhunk
Starting Member

7 Posts

Posted - 2012-12-13 : 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.
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-12-13 : 08:10:50
You are very welcome, IH!
Go to Top of Page
   

- Advertisement -