IF OBJECT_ID('TABELANOTAS','U') IS NOT NULL
DROP TABLE TABELANOTAS
CREATE TABLE TABELANOTAS (DATA DATE, NUMNOTAS INT)
DECLARE @DATAINICIAL DATE
DECLARE @DATAFINAL DATE
DECLARE @NUMNOTAS INT
SET @DATAINICIAL = '20170101'
SET @DATAFINAL = '20170110'
WHILE @DATAINICIAL <= @DATAFINAL
BEGIN
SELECT @NUMNOTAS = COUNT(*) FROM [NOTAS FISCAIS]
WHERE DATA = @DATAINICIAL
INSERT INTO TABELANOTAS (DATA, NUMNOTAS)
VALUES (@DATAINICIAL, [dbo].[NumeroNotas](@DATAINICIAL))
SELECT @DATAINICIAL = DATEADD(DAY, 1, @DATAINICIAL)
END
SELECT * FROM TABELANOTAS