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.
Author |
Topic |
viper
Starting Member
6 Posts |
Posted - 2009-09-21 : 22:48:25
|
quote]Hi I have a Query to convert Datetime as follows
(SELECT CAST(MONTH([Date]) AS varchar) + '-' + CAST(YEAR([Date]) AS varchar) AS 'MonthYear', SUM(Amount) AS 'Total' quote: Question How can I can I convert DateTime to Jan-2009 instead of 1-2009 Thank you[/quote]VIPER |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-09-21 : 22:54:30
|
use datename(month, [Date]) KH[spoiler]Time is always against us[/spoiler] |
|
|
viper
Starting Member
6 Posts |
Posted - 2009-09-23 : 20:06:38
|
THANKS KHTAN FOR YOUR REPLYVIPER |
|
|
viper
Starting Member
6 Posts |
Posted - 2009-09-23 : 22:50:05
|
quote:
This is my Updated SQL SELECT MonthYear, SUM(Total) AS TotalFROM (SELECT CAST(DATENAME(M,Date) AS varchar) + '-' + CAST(YEAR([Date]) AS varchar) AS 'MonthYear', SUM(Amount) AS 'Total' FROM Neon GROUP BY DATENAME(M,Date) UNION ALL SELECT CAST(DATENAME(M,Date) AS varchar) + '-' + CAST(YEAR([Date]) AS varchar) AS 'MonthYear', SUM(Amount) AS 'Total' FROM InsuranceNeon GROUP BY DATENAME(M,Date) AS tbTempGROUP BY MonthYear quote:
I get the following error " Incorrect syntax near the keyword 'AS' "Can anyone HelpTank youVIPER |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-24 : 02:55:00
|
GROUP BY DATENAME(M,Date) AS tbTempGROUP BY MonthYearshould beGROUP BY DATENAME(M,Date) , MonthYearMadhivananFailing to plan is Planning to fail |
|
|
viper
Starting Member
6 Posts |
Posted - 2009-09-25 : 18:21:42
|
THANKS KHTANVIPER |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-29 : 02:16:17
|
quote: Originally posted by madhivanan GROUP BY DATENAME(M,Date) AS tbTempGROUP BY MonthYearshould beGROUP BY DATENAME(M,Date) , MonthYearMadhivananFailing to plan is Planning to fail
So, you didn't see my previous reply? MadhivananFailing to plan is Planning to fail |
|
|
viper
Starting Member
6 Posts |
Posted - 2009-09-29 : 23:10:29
|
Thanks madhivananfor your info.VIPER |
|
|
|
|
|
|
|