clear markdown compare help donate or buy diddy dollings comments/suggestions/bugs a leap of faith? bible365
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 710119 fiddles created (14341 in the last week).

CREATE TABLE Calendar(cDate datetime, cDay int, cDayOfWeek int, cDayName varchar(20), cMonth int); DECLARE @date date = '20180101'; WHILE @date <= '20180131' BEGIN INSERT INTO Calendar VALUES (@date, DAY(@date), DATEPART(weekday, @date), DATENAME(weekday, @date), MONTH (@date)); SET @date = DATEADD(day, 1, @date); END CREATE TABLE Mov (Day_no date, Balance int); INSERT INTO Mov VALUES ('20180101', 5000), ('20180110', 10000), ('20180115', 12000);
34 rows affected
 hidden batch(es)


SELECT cDAte, (SELECT TOP 1 Balance FROM Mov WHERE Day_no <= cDate ORDER BY Day_no DESC) Balance FROM Calendar WHERE cMonth = 1;
cDAte Balance
2020-01-14 05:09:21 5000
2020-01-14 05:09:21 5000
2020-01-14 05:09:21 5000
2020-01-14 05:09:21 5000
2020-01-14 05:09:21 5000
2020-01-14 05:09:21 5000
2020-01-14 05:09:21 5000
2020-01-14 05:09:21 5000
2020-01-14 05:09:21 5000
2020-01-14 05:09:21 10000
2020-01-14 05:09:21 10000
2020-01-14 05:09:21 10000
2020-01-14 05:09:21 10000
2020-01-14 05:09:21 10000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
2020-01-14 05:09:21 12000
 hidden batch(es)