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 |
|
pravin14u
Posting Yak Master
246 Posts |
Posted - 2008-04-19 : 06:40:15
|
| I have 2 columnsRecordDate(DateTime)Quantity(Int)I would like to group the data quarter wise like,Quarter 1 500Quarter 2 340Quarter 3 450Quarter 4 400Note: Say quarters are fixed from Jan-Mar,Apr-Jun etc.,Prakash.PThe secret to creativity is knowing how to hide your sources! |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-04-19 : 06:54:18
|
| select q, qty = sum(qty)from(select q = 'Quarter ' + convert(varchar(10),datepart(qq,RecordDate)), qty = sum(Quantity)from tbl) agroup by q==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
PeterNeo
Constraint Violating Yak Guru
357 Posts |
Posted - 2008-04-19 : 07:12:55
|
| try this with slight modificationsselect Year, q, qty = sum(qty)from(select Year(RecordDate) as Year, q = 'Quarter ' + convert(varchar(10),datepart(qq,RecordDate)), qty = sum(Quantity)from tblGroup by Year(RecordDate), convert(varchar(10),datepart(qq,RecordDate))) agroup by Year,q |
 |
|
|
|
|
|
|
|