set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
ALTER FUNCTION [dbo].[F_CoundBind_MatePeople]
(
-- Add the parameters for the function here
@RegID INT,--传入函数的参数
@Fallnum INT--传入函数的参数
)
RETURNS varchar(100)
AS
BEGIN
DECLARE @PeopleName varchar(50),@LastName varchar(100)
SET @LastName = ''
-- Declare the return variable here
DECLARE people_cursor CURSOR FOR
SELECT [name] FROM t_mate_people
WHERE regid = @Regid and Fallnum = @Fallnum
OPEN people_cursor
-- Perform the first fetch and store the values in variables.
-- Note: The variables are in the same order as the columns
-- in the SELECT statement.
FETCH NEXT FROM people_cursor
INTO @PeopleName
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
-- Concatenate and display the current values in the variables.
SET @LastName = @PeopleName + ',' + @LastName
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM people_cursor
INTO @PeopleName
END
CLOSE people_cursor
DEALLOCATE people_cursor
-- Add the T-SQL statements to compute the return value here
-- Return the result of the function
RETURN @LastName
END