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 2005 Forums
 Transact-SQL (2005)
 Count of records per year

Author  Topic 

baska123
Yak Posting Veteran

64 Posts

Posted - 2007-08-03 : 16:28:16
We have a date stored as a sys date in a table. We want to count how many records are under each year. Any ideas for SQL statement.

Thanks

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-08-03 : 16:39:54
COUNT(*), GROUP BY YEAR(Datecolumn).

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-08-03 : 16:40:29
or COUNT(*) Between Date1 and Date2.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

baska123
Yak Posting Veteran

64 Posts

Posted - 2007-08-03 : 17:22:40
Thanks for hints.
This is what worked for me

SELECT COUNT(*), date_row
FROM TAXBUS.TRANS T
GROUP BY to_char(T.DT)
Go to Top of Page

baska123
Yak Posting Veteran

64 Posts

Posted - 2007-08-03 : 17:27:57
One correction

SELECT COUNT(*)
FROM TAXBUS.TRANS T
GROUP BY to_char(T.DT, 'yyyy')
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-08-03 : 17:49:21
quote:
Originally posted by baska123

One correction

SELECT COUNT(*)
FROM TAXBUS.TRANS T
GROUP BY to_char(T.DT, 'yyyy')



That's Oracle SQL, not Microsoft SQL Server TSQL.



CODO ERGO SUM
Go to Top of Page
   

- Advertisement -