Hi satabeach,
Refer the below sample test query.
SQL
DECLARE @Products AS TABLE (Product_ID INT,Sold_by INT,Qty INT,From_date DATE,To_date DATE)
INSERT INTO @Products VALUES(3,12,7,'2013-01-05','2013-01-07')
INSERT INTO @Products VALUES(6,22,14,'2013-01-06','2013-01-10')
INSERT INTO @Products VALUES(8,11,9,'2013-02-05','2013-02-11')
SELECT * FROM @Products
DECLARE @FromDate DATE = '2013-01-01'
DECLARE @ToDate DATE = '2013-01-08'
CREATE TABLE #temp(From_Date DATE,Product_Id INT)
WHILE @FromDate <= @ToDate
BEGIN
IF EXISTS (SELECT From_date FROM @Products WHERE From_date = @FromDate)
BEGIN
DECLARE @Product_ID INT = (SELECT Product_ID FROM @Products WHERE From_date = @FromDate)
INSERT INTO #temp VALUES(@FromDate,@Product_ID)
END
ELSE
BEGIN
INSERT INTO #temp VALUES(@FromDate,NULL)
END
SET @FromDate = DATEADD(dd,1,@FromDate)
END
SELECT * FROM #temp
DROP TABLE #temp
OutPut