• Had a few minutes to kill... Here's a solution using what is commonly referred to as the "Quirky Update". I included the code to make sample data...

    USE tempdb

    GO

    IF OBJECT_ID('tempdb.dbo.dimdate') IS NOT NULL DROP TABLE dbo.DimDate;

    IF OBJECT_ID('tempdb.dbo.totalsdata') IS NOT NULL DROP TABLE dbo.totalsdata;

    create table dimdate (datevalue date);

    create table totalsdata (datevalue date, totalvalue int);

    GO

    DECLARE @startdate date=getdate();

    -- populate dimDate

    WITH iTally(n) AS

    (SELECT TOP(13) ROW_NUMBER() OVER (ORDER BY (SELECT NULL))-1

    FROM sys.all_columns)

    INSERT dbo.DimDate

    SELECT dateadd(day,n,@startdate) AS datevalue

    FROM iTally;

    -- populate dimDate

    WITH TotalsData_prep AS

    (SELECT datevalue, totalvalue

    FROM (VALUES (3,55),(7,66),(9,77),(11,88)) t(datevalue,totalvalue))

    INSERT dbo.TotalsData

    SELECTdateadd(day,datevalue,@startdate) AS datevalue,

    totalvalue

    FROM TotalsData_prep;

    GO

    -- using the "Quirky Update"

    DECLARE @x TABLE(datevalue date, tv int);

    DECLARE @TV int=0;

    INSERT @x

    SELECT d.datevalue, coalesce(t.totalvalue,0)

    FROM dimdate d

    LEFT JOIN dbo.TotalsData t

    ON d.datevalue=t.datevalue;

    UPDATE @x

    SET @TV=tv= CASE WHEN tv<>0 THEN tv ELSE @TV END

    FROM dbo.TotalsData

    SELECT *

    FROM @x;

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001