日期:2014-05-18 浏览次数:20487 次
不用写过程,直接 select role1,role2.role3 from tb where id=4 如果真想写过程 create function getRole(@id) returns @tb table(role1 bit,role2 bit,role3 bit) as begin insert @tb select role1,role2.role3 from tb where id=@id return end 用的时候 select * from dbo.getRole(4)
------解决方案--------------------
突然明白了你的意思
--首先保证id=4的数据唯一性 create function getRole(@id) returns char(20) as begin declare @role char(20) set @role='' select @role=@role+'role1/'+role1+' ' from tb where id=@id select @role=@role+'role2/'+role2+' ' from tb where id=@id select @role=@role+'role3/'+role3+' ' from tb where id=@id return @role end 用的时候select dbo.getRole(4)
------解决方案--------------------
刚才的有点错误,修改了一下
过程,
create function getRole(@id int) returns varchar(100) as begin declare @role varchar(100) set @role='' select @role=@role+'role1/'+cast(role1 as varchar)+' ' from tb where id=@id select @role=@role+'role2/'+cast(role2 as varchar)+' ' from tb where id=@id select @role=@role+'role3/'+cast(role3 as varchar)+' ' from tb where id=@id return @role end
------解决方案--------------------
楼上的,你写那么多和下面这句有区别么?
select 'role1'+role1+' '+'role2'+role2+' '+'role3'+role3 from tb where...
------解决方案--------------------