I want to write a function that returns in INT which is the number of records that match a certain criteria.
I tried this, and it runs… but it keeps quiet – it doesn’t return anything. I guess it just runs select in the background.
ALTER FUNCTION [dbo].[f_InboundCallsPerUser](@p_User varchar(50), @p_sd datetime, @p_ed datetime)
RETURNS INT
WITH EXECUTE AS CALLER
AS
BEGIN
Return(SELECT COUNT(*)
FROM CallDetail
WHERE LocalUserID = @p_user
AND InitiatedDate BETWEEN @p_sd AND @p_ed
AND UPPER(CallDirection) = 'OUTBOUND'
AND LineDurationSeconds > 0);
END;
How do you do that?
Use
I guess you are probably
EXEC-ing it. in which case you need to doto see the returned value.