CREATE FUNCTION NumeroNotas (@DATA DATE) RETURNS INT
AS BEGIN
DECLARE @NUMNOTAS INT
SELECT @NUMNOTAS = COUNT(*) FROM [NOTAS FISCAIS]
WHERE [DATA] = @DATA
RETURN @NUMNOTAS
END
DECLARE @DATA DATE = '20170101'
SELECT @DATA AS DATA, [dbo].[NumeroNotas](@DATA) AS QTD_NOTAS