| Author |
Topic |
|
Trininole
Yak Posting Veteran
83 Posts |
Posted - 2012-04-09 : 10:22:06
|
| I am trying to pull some data from January 2011 till March 2012 by month. What would the syntax be for that?Roger DeFour |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2012-04-09 : 10:30:43
|
| That all depends on what your data looks like. Do you have a field that is a date data type? Also, when you say you want this by month, do you mean that you have, say, records for various days in a month and you need them grouped into just one record for that month?JimEveryday I learn something that somebody else already knew |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-04-09 : 10:31:19
|
select dateadd(month, dateadiff(month, 0, datecol), 0), <aggregate function> ( <some column> )from sometablewhere datecol >= '2011-01-01'and datecol < '2012-04-01'group by dateadd(month, dateadiff(month, 0, datecol), 0) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Trininole
Yak Posting Veteran
83 Posts |
Posted - 2012-04-09 : 10:52:03
|
| I need them grouped into one record by month.Roger DeFour |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-04-09 : 10:56:47
|
quote: Originally posted by Trininole I need them grouped into one record by month.Roger DeFour
what do you mean ?Please provide some sample data and expected result KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Trininole
Yak Posting Veteran
83 Posts |
Posted - 2012-04-09 : 11:09:01
|
| well what is the syntax for displaying the month name in sql?Roger DeFour |
 |
|
|
Trininole
Yak Posting Veteran
83 Posts |
Posted - 2012-04-09 : 11:09:42
|
| For example January, February, March etc.Roger DeFour |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-04-09 : 11:10:29
|
quote: Originally posted by Trininole well what is the syntax for displaying the month name in sql?Roger DeFour
datename( month, <datecol> ) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-09 : 11:10:44
|
quote: Originally posted by Trininole For example January, February, March etc.Roger DeFour
use DATENAME(mm,yourdatecolumn)------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|