Sunday 22 July 2012

creating a function in sql server 2008 r2

create a function in sql server:

take the Scalar-function.

Function:

create FUNCTION Getwrongnumbercount
(
-- Add the parameters for the function here
@createdate date,
@uname varchar(50)

)
RETURNS int
AS
BEGIN
-- Declare the return variable here
DECLARE
@ResultVar int

-- Add the T-SQL statements to compute the return value here
set @ResultVar = (select count(*) from FilteredPhoneCall where  (CONVERT(DATETIME, FLOOR(CONVERT(FLOAT, createdon))) = @createdate) and (statuscodename = 'Wrong Number' or statuscodename = 'No Response') and (createdbyname = @uname ))

-- Return the result of the function
RETURN @ResultVar

END
GO

No comments:

Post a Comment