create function dbo.f_str(@id int,@col1 varchar(10)) returns varchar(100)
as
begin
declare @str varchar(1000)
set @str = ''
select @str = @str + ',' + cast(col2 as varchar) from tb where id = @id and col1 = @col1
set @str = right(@str , len(@str) - 1)
return @str
end
go--调用函数
select id , col1 , col2 = dbo.f_str(id,col1) from tb group by id,col1drop function dbo.f_str-----------------------------------
放在存储过程里面提示必须声明变量@id
as
begin
declare @str varchar(1000)
set @str = ''
select @str = @str + ',' + cast(col2 as varchar) from tb where id = @id and col1 = @col1
set @str = right(@str , len(@str) - 1)
return @str
end
go--调用函数
select id , col1 , col2 = dbo.f_str(id,col1) from tb group by id,col1drop function dbo.f_str-----------------------------------
放在存储过程里面提示必须声明变量@id
(
-- Add the parameters for the function here
@Id int
)
RETURNS varchar(500)
AS
BEGIN
declare @str varchar(500)
RETURN @strEND调用
select dbo.GetPath(c.id) as 'Path' from content c