[Solved] Need to sum the results of a query


Try this one –

CREATE FUNCTION dbo.udf_getCountCallOnDate
(
      @DateFrom DATETIME
    , @DateTo DATETIME
)
RETURNS INT
AS
BEGIN

    RETURN (
        SELECT SUM(CallsTakenOnDate) 
        FROM dbo.PhoneCalls
        WHERE DateOfWork BETWEEN @DateFrom AND @DateTo
    )

END

SELECT 
  DateOfWork = CONVERT(VARCHAR(10), t.DateOfWork, 111)
, [Count] = SUM(t.CallsTakenOnDate) 
FROM dbo.PhoneCalls t
WHERE DateOfWork BETWEEN @DateFrom AND @DateTo
ORDER BY t.DateOfWork

0

solved Need to sum the results of a query