Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
how to get the financial year only for mar values for every year
Posted

Hi,

try this,
SQL
SELECT * FROM YourTable WHERE DATEPART(MONTH, FinancialYear)= 3

-- FinancialYear would be column of YourTable

this query will give details from the table if the month is MARCH.
 
Share this answer
 
Comments
StianSandberg 23-Jul-12 7:54am    
SELECT * FROM YourTable WHERE MONTH(MyDateColumn) = 3
Would also work..
Based upon what little you gave us in the question, here is an answer that you will have to adapt to your particular environment but which should work:
SQL
SELECT rowMonth, rowYear, SUM(rowMoneyData) AS Total
FROM (
   SELECT Month(rowDate) AS rowMonth, Year(rowDate) AS rowYear, rowMoneyData
   FROM yourTable) AS convertedTable
WHERE rowMonth = 3
GROUP BY rowYear, rowMonth

What this does is it first creates a sub-query that includes just the data you need and gives you month and year numbers for each row. Then we use that sub-query in our main query to group by and filter. Since you wanted just March data, I filtered it by month number 3.

You could do this without the sub-query but it wouldn't be as performant because you would need to do the conversion to month twice instead of once (once in the Group By and once in the Where).

The results of this query would be the total for March for each year on a separate line.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900