Monday, October 22, 2012

Function for returning single scaler value in sql server


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

-- =============================================
-- Author: Ajay Kumar
-- Create date: 22-10-2012
-- Description: This function used to get values for allocated users
-- =============================================
CREATE FUNCTION [dbo].[getAllocatedUsers]
(
-- Add the parameters for the function here
@CId varchar(20)
)
RETURNS varchar(20)
AS
BEGIN
-- Declare the return variable here
declare @AllocatedTo varchar(20)

-- Add the T-SQL statements to compute the return value here
SELECT @AllocatedTo=cname from [exec] where cid=@CId

-- Return the result of the function
RETURN @AllocatedTo
END

No comments:

Post a Comment