title: Fill Missing Dates between two dates in SQL Server
body: <p>I have temp table with following data</p>
  
  <p><img src="https://i.stack.imgur.com/Dt3mt.png" alt="Temp Table with customer&#39;s data"></p>
  
  <p>All i want to fill missing dates between start date and end date and repeat the running balance column until new balance is not shown. Same repetition is also required for every customer. When new balance is shown it will be repeat again for next value.</p>
  
  <p>Also, i want to pick max transaction date of every day.</p>
  
  <p>any help?</p>
  
  <p><a href="https://i.stack.imgur.com/Dt3mt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dt3mt.png" alt="[1]: https://i.stack.imgur.com/Dt3mt.png"></a></p>
  
  <pre><code>DECLARE @Date DATETIME, @StartDate DATETIME, @EndDate DATETIME, @Counter INT, @TotalDays INT
  
  SET @Date = '2018-11-25'
  
  SET @StartDate = CONVERT(varchar, dateadd(month,datediff(month,0,@Date),0), 111)
  SET @EndDate = CONVERT(varchar, dateadd(day,-1,dateadd(month,datediff(month,-1,@Date),0)), 111)
  SET @Counter = 0
  SET @TotalDays = DAY(@EndDate)
  ----------------------------------------------------------------
  
  CREATE TABLE #Customers
  (
      ID BIGINT IDENTITY(1,1),
      Customer_ID BIGINT,
      Transaction_Date DATETIME,
      Serial_No INT
  )
  
  INSERT INTO #Customers
  (Customer_ID, Transaction_Date, Serial_No)
  
  SELECT tc.Customer_Id, tc.Transaction_Date, tc.Serial_No
  
  FROM Transaction_Main AS tm
  JOIN Transaction_Detail AS td
      ON td.Transaction_Date = tm.Transaction_Date 
      AND td.Transaction_No = tm.Transaction_No
  JOIN Transaction_Customer AS tc
      ON tc.Transaction_Date = td.Transaction_Date
      AND tc.Transaction_No = td.Transaction_No
      AND tc.Serial_No = td.Serial_No
  
  WHERE tm.Transaction_Status IN ('A', 'P')
  AND tm.Transaction_Date BETWEEN @StartDate  AND @EndDate + ' 23:59:59'
  AND td.Transaction_Date BETWEEN @StartDate  AND @EndDate + ' 23:59:59'
  AND tc.Transaction_Date BETWEEN @StartDate  AND @EndDate + ' 23:59:59'
  AND tc.Customer_Id = 21
  AND tm.Transaction_Type &lt;&gt; 4
  </code></pre>