Here is my next level of try
select name,case when DataReceived IS not null then RecordsCount
else (select top 1 DATEADD(DAY, c.DaysInLate, md.MyDate) from #data d2 join #company c on d2.Name = c.Name where c.Name = 'microsoft') end as MyNewValue
from MyDates md
left join #data d on d.DataReceived = md.MyDate
from your query the exptected output has to be below,
microsoft2013-08-01 00:00:00.0001000
microsoft2013-08-02 00:00:00.0001001
microsoft2013-08-03 00:00:00.0001002
microsoft2013-08-04 00:00:00.0001003
microsoft2013-08-05 00:00:00.0001005
microsoft2013-08-06 00:00:00.0001005
microsoft2013-08-07 00:00:00.0001006
microsoft2013-08-08 00:00:00.0001007
microsoft2013-08-09 00:00:00.0001004
microsoft2013-08-10 00:00:00.0001033
microsoft2013-08-11 00:00:00.0001020
NULL2013-08-12 00:00:00.0002013-08-27 00:00:00.000
NULL2013-08-13 00:00:00.0002013-08-28 00:00:00.000
NULL2013-08-14 00:00:00.0002013-08-29 00:00:00.000
NULL2013-08-15 00:00:00.0002013-08-30 00:00:00.000
NULL2013-08-16 00:00:00.0002013-08-31 00:00:00.000
NULL2013-08-17 00:00:00.0002013-09-01 00:00:00.000
NULL2013-08-18 00:00:00.0002013-09-02 00:00:00.000
NULL2013-08-19 00:00:00.0002013-09-03 00:00:00.000
NULL2013-08-20 00:00:00.0002013-09-04 00:00:00.000
NULL2013-08-21 00:00:00.0002013-09-05 00:00:00.000
NULL2013-08-22 00:00:00.0002013-09-06 00:00:00.000
NULL2013-08-23 00:00:00.0002013-09-07 00:00:00.000
NULL2013-08-24 00:00:00.0002013-09-08 00:00:00.000
NULL2013-08-25 00:00:00.0002013-09-09 00:00:00.000
NULL2013-08-26 00:00:00.0002013-09-10 00:00:00.000
NULL2013-08-27 00:00:00.0002013-09-11 00:00:00.000
NULL2013-08-28 00:00:00.0002013-09-12 00:00:00.000
NULL2013-08-29 00:00:00.0002013-09-13 00:00:00.000
NULL2013-08-30 00:00:00.0002013-09-14 00:00:00.000
NULL2013-08-31 00:00:00.0002013-09-15 00:00:00.000
but it's not happening. please help me on this. after getting the above result then have to make the pivot for final result