SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 dont know how to retrieve it
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

indianhunk
Starting Member

7 Posts

Posted - 12/09/2012 :  04:21:23  Show Profile  Reply with Quote
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  Show Profile  Reply with Quote
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 - 12/09/2012 :  12:27:41  Show Profile  Reply with Quote
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 - 12/13/2012 :  03:47:57  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/13/2012 :  08:10:50  Show Profile  Reply with Quote
You are very welcome, IH!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000