I have database which has data of past 2 years.
I want to get that data for current financial year.
(Here financial year is 1st april to 31st of March)
This query returns data for current calender year i.e. [Jan-to-Dec]
SELECT DATENAME(MONTH, DATE) AS MonthName,
SUM(NetAMOUNT) AS dsfd from SALESMASTER
GROUP BY DATEPART(MONTH, DATE), DATENAME(MONTH, DATE)
ORDER BY DATEPART(MONTH, DATE)
I want to see the same data in the form of financial year i.e. [April-to-March]
just take care financial year involves 9 months of previous year and 3 months of current year.
You may check the posts here and see it is helpful for you:http://www.bigresource.com/Tracker/Track-ms_sql-8xeNr2qA/
how is the date stored, if stored using a date object or a timestamp its a piece of cake
if its stored using text dates, punch out your dbase designer
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = DATEADD(dd,0, DATEDIFF(dd,0, DATEADD( mm, -(((12 + DATEPART(m, getDate())) - 4)%12), getDate() ) - datePart(d,DATEADD( mm, -(((12 + DATEPART(m, getDate())) - 4)%12),getDate() ))+1 ) )
SET @EndDate = DATEADD(SS,-1,DATEADD(mm,12,@StartDate))