I have this data that shows consolidated report grouped by year. What I have used is a simple
GROUP BY YEAR(BookingDate) clause and everything works fine. But what I want is the year to be financial year (1 April to 31 May) and not the normal calender year, so how can I do this? The query is..
SELECT
CONVERT(VARCHAR(25), c.Duration) AS Duration,
COALESCE(c.totalbookings, 0) AS totalbookings
FROM
(SELECT
YEAR(bookingdate) AS Duration,
COUNT(*) AS totalbookings
FROM
entbookings
WHERE BranchId=@Branchid
GROUP BY YEAR(bookingdate)
) AS c
LEFT OUTER JOIN
(SELECT
Duration,
SUM(totalitems) 'bkdqty'
FROM
[yrItemWISeTotalQty] (@BranchId) AS BkdQty
GROUP BY Duration
) AS d
ON c.Duration = d.Duration
The yrItemWISeTotalQty is defined as
CREATE FUNCTION [dbo].[yrItemWiseTotalQty]
(
@BrachId VARCHAR(MAX)
)
RETURNS TABLE AS
RETURN
SELECT
YEAR(EntBookings.BookingDate) AS Duration,
Sum(dbo.EntBookings.ItemCost) AS totalcost,
WHERE EntBookings.BranchId = @BrachId
GROUP BY Year(EntBookings.BookingDate)
Again, I am using GROUP BY Year() that does the work great, but I need to modify it to take the fy i.e. (1 April to 31 March). How can I do it?
try this: