use GuangDongTest
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--根据---得到 IDs
create Function [dbo].[GetIds]
(@pid int)
returns varchar(10)
as
begin
declare @v varchar(10) --声明一个游标
set @v=''
declare @i int
declare mycur cursor for --循环得到IDS
select b.id from 表 b--是别名 where b.ID=@pid order by b.id
open mycur
fetch next from mycur into @i
while @@FETCH_STATUS=0
begin
set @v=@v+cast(@i as varchar)+',' --IDs 累加用逗号隔开
fetch next from mycur into @i
end
close mycur
deallocate mycur
return @v
end
=============================
SQL 查出多条数据 用逗号隔开 合并某一列的 标量函数
最新推荐文章于 2024-01-11 15:16:07 发布