将表名为TableName字段为Name的字段的值拼接起来,返回结果name1,name2,name...
CREATE
FUNCTION
convertMultiRowsToChar(
@id
int
)
RETURNS
varchar
(
50
)
AS BEGIN DECLARE @sql varchar ( 50 )
SET @sql = ''
SELECT @sql = @sql + ' , ' + cast (Name AS varchar )
FROM TableName
WHERE Id = @id RETURN stuff ( @sql , 1 , 1 , '' ) END
AS BEGIN DECLARE @sql varchar ( 50 )
SET @sql = ''
SELECT @sql = @sql + ' , ' + cast (Name AS varchar )
FROM TableName
WHERE Id = @id RETURN stuff ( @sql , 1 , 1 , '' ) END