ALTER function [dbo].[GetOwnerString](
@Id int)
returns nvarchar(200)
as
begin
 declare @result nvarchar(200),@owner nvarchar(20);
 
 set @result='';
 declare owner_cursor cursor for select Owner from InProcess where ProjectId=@Id;
 
 open owner_cursor;
 
 fetch next from owner_cursor into @owner;
 
 while(@@FETCH_STATUS=0)
  begin
   if(@result='')
    set @result=@owner;
   else
    set @result=@result+','+@owner;
   
   fetch next from owner_cursor into @owner;
  end
 
 close owner_cursor;

 deallocate owner_cursor;
 
 return @result;
 
end

 

对于函数, 做一些简单逻辑操作还是可以的,对性能的影响不大. 在涉及多表操作时,就应该注意表间查询带来的执行时间的消耗.

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
猜你喜欢
  • 2021-08-13
  • 2022-02-17
  • 2022-12-23
  • 2022-01-25
  • 2021-07-10
  • 2022-12-23
相关资源
相似解决方案