-1

How to access the data from MSSQL table

User will give only month(3) and financial year(2013-14), how can I retrieve the progress up to last month (previous month) and up to month (this month) while data has been inserted from jun-2013 to march-2014

I have tried but I have given like month 3 and financial year 2013-14 but its calculate only two month data while it should be calculate Apr-2013 to Mar-2014 data

My table structure is like

+--------+-------+------+---------+
| amount | month | year | finyear |
+--------+-------+------+---------+
| 12456  |   2   | 2013 | 2013-14 |
+--------+-------+------+---------+

thanks

Jesuraja
  • 3,774
  • 4
  • 24
  • 48
  • If your user supplies month 3, and financial year (fiscal year) 2013-2014, you *actually* want results for the date range 2013-04-01 to . . . when? (*This* month is May, 2014. *Previous* month is April, 2014.) – Mike Sherrill 'Cat Recall' May 30 '14 at 11:27
  • I think the month here is calendar month and not related to the fiscal year at all. I don't understand the question either. It says data is from june 2013 to march 2014 but evaluation from april 2013 to march 2014. ?? – Martin K. May 30 '14 at 11:29
  • You haven't defined what the financial year is, is it January to December? Or something else? – StevieG Jun 02 '14 at 13:33

1 Answers1

0

Something like this should do it:

SELECT SUM(a.amount) + SUM(b.amount)
FROM table a
INNER JOIN table b ON b.year = a.year - 1
WHERE a.finyear = '2013 - 14'
AND a.month <= 3
AND b.month > 3

Although your data structure and example data is pretty confusing..

StevieG
  • 8,639
  • 23
  • 31