Answer:
SELECT y.[Date], tbl. [Income], tbl. [Expenditure], (
SELECT SUM (ISNULL (tbl.[ Revenue], 0)-isnull (tbl.[ Expenses], 0)) from TBL WHERE [date]<=y.[Date]) as [balance]
From TBL Right JOIN (
SELECT DATEADD (DD, N.I, DATEADD (DD, 1-day (m.minday), m.minday)) as [date]
From (
SELECT 0 As I
UNION all SELECT 1
UNION All SELECT 2
UNION All SELECT 3
UNION All SELECT 4
UNION all SELECT 5
UNION All SELECT 6
UNION All SELECT 7
UNION All SELECT 8
UNION All SELECT 9
UNION All SELECT 10
UNION All SELECT 11
UNION All SELECT 12
UNION All SELECT 13
UNION All SELECT 14
UNION All SELECT 15
UNION All SELECT 16
UNION all SELECT 17
UNION All SELECT 18
UNION all SELECT 19
UNION All SELECT 20
UNION All SELECT 21
UNION all SELECT 22
UNION all SELECT 23
UNION All SELECT 24
UNION all SELECT 25
UNION all SELECT 26
UNION all SELECT 27
UNION all SELECT 28
UNION all SELECT 29
UNION All SELECT 30
UNION all SELECT 31
N
(
SELECT MIN (date) as Minday
From TBL
GROUP by DATEDIFF (month, 0, date)
) M
WHERE DATEDIFF (MM, DATEADD (DD, N.I, DATEADD (DD, 1-day (m.minday), M.minday)), M.minday) =0) as Y
On TBL. [Date]=y. Date
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.