Create a Function in sqlserver 2008 to get Names from table by passing Ids as a Parameter:


The following is the Create function to get names by passing ids as a parameters.

CREATE FUNCTION GetNameById
(
    @id varchar(100)
)
RETURNS varchar(max)
AS
BEGIN
               
    declare @output varchar(max)
    select @output = COALESCE(@output + ', ', '') + Name
    from TableName
    where Id in (select * from Split(@id,','))

    return @output
END




0 comments:

Post a Comment