22,209
社区成员
发帖
与我相关
我的任务
分享
if object_id('staff') is not null
drop table staff
go
create table staff(staff_id varchar(50),staffname varchar(50))
insert into staff select '006987','aaa'
insert into staff select '006877','bbb'
insert into staff select '006988','ccc'
insert into staff select '006983','ddd'
insert into staff select '006980','eee'
insert into staff select '006981','fff'
insert into staff select '006982','ggg'
insert into staff select '006983','hhh'
go
if object_id('get_staff_id') is not null
drop function get_staff_id
go
create function get_staff_id()--这加参数
returns varchar(8000)
as
begin
declare @r varchar(8000)
select @r=isnull(@r+',','')+staff_id from staff--这加条件
return @r
end
go
select dbo.get_staff_id() as 结果