create table student
(
username varchar(50),
fruit varchar(200)
)
insert into student values('小王','香焦' )
insert into student values('小王','苹果' )
insert into student values('小王','黄瓜' )
insert into student values('chx','番茄' )
insert into student values('chx','牛奶' )
--创建一个函数,当我们输入一个名字时把他喜欢的水果给全部显示
create function dbo.fn_Fruit
(
@name varchar(50)
)
returns varchar(200)
as
begin
declare @fruit as varchar(50)
set @fruit=''
select @fruit=@fruit+fruit+';' from student where username=@name
return @fruit
end