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)
 query return results month wise

Author  Topic 

pareekfranksoul
Starting Member

26 Posts

Posted - 2008-12-15 : 04:58:19
Table Structure:

id message date
1 hello 2008-12-15 11:30:00
2 hi 2008-11-15 11:30:00
3 abcd 2008-11-15 11:30:00
4 13245g 2008-11-15 11:30:00
5 by 2008-11-15 11:30:00
6 boss 2008-10-15 11:30:00



Need query which will return results month wise ie:

december

1 hello 2008-12-15 11:30:00

november


2 hi 2008-11-15 11:30:00
3 abcd 2008-11-15 11:30:00
4 13245g 2008-11-15 11:30:00
5 by 2008-11-15 11:30:00

october

6 boss 2008-10-15 11:30:00

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-15 : 05:14:05
I think this is a presentation issue.
Is there a way you can group data with your report engine?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2008-12-15 : 05:18:32
SELECT * FROM TableName
where -- To use Numeric
DatePart(Month,[Date])='12'
OR
-- To use Month Name
DateName(Month,[Date])='December'
Go to Top of Page

pareekfranksoul
Starting Member

26 Posts

Posted - 2008-12-15 : 05:23:23
yes its a presentation issue but can i get it solved with sql query.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2008-12-15 : 06:13:08
try this i am not sure

SELECT DISTINCT DATENAME(MM, date) FROM urtable WHERE DATEPART(mm,date ) = 12
SELECT * FROM urtable WHERE DATEPART(mm,date ) = 12
repeat query for all months
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-15 : 07:28:14
just bring data as it is from table and do the formatting at your front end application. Formatting the output is not purpose of sql server. it should be done by your front end code

Go to Top of Page
   

- Advertisement -