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
 General SQL Server Forums
 New to SQL Server Programming
 Add a New coloum to mention Quarter Number

Author  Topic 

anuraag205
Yak Posting Veteran

58 Posts

Posted - 2012-08-27 : 06:04:24
i have a table containing years, months and sales as coloumns. I want to add a new coloum which specifies the name of quarter that the month belongs to ..fo a financial calender year. apr-may-june=Q1, JULY -AUG-sep=Q2, OCT-NOV-dec=q3, Jan -Feb-mar=q4....can anyone help???

help is my select statement::

SELECT
DATENAME(Year,BookingDate) as Year,
DATENAME(Month,BookingDate) as Month,
COUNT(InvoiceNumber) as [Total Bookings],
Sum(NegotiatedSellPrice) as [Total Sale Price]

I also wanted to sum the amount quarterly and find the % difference of sales and bookings from previous quarter???

Please help

Thanks

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-08-27 : 06:09:28
Easier to have a calendar table with the dates and attributes then just join to that.
'Q' + convert(varchar(1),(datepart(mm,BookingDate)-1)%3+1)

For the calculation would ddefiitely use the calendar table.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

anuraag205
Yak Posting Veteran

58 Posts

Posted - 2012-08-27 : 08:57:14
Thanks for that...but i tried in report builder to get that...am not hands on @ sql queries. Thanks anyways...u r reply will help me futher

Thanks
Go to Top of Page
   

- Advertisement -