SQL 游标 遍历

ALTER FUNCTION [dbo].[SumString] 

( 

  @userId nvarchar(40),  

  @selectName  nvarchar(4000)

) 

RETURNS nvarchar(4000) 

AS 

BEGIN 



declare @Str nvarchar(4000) 

declare @ProductName nvarchar(4000) 

set @Str =''

declare  pcurr cursor for select '"'+@selectName+'"' from  MLK_PDP.dbo.ReportView

open pcurr  

fetch next from pcurr into @ProductName  

while (@@fetch_status = 0)  

begin  

 set @Str=@Str+@ProductName

 fetch next from pcurr into @ProductName  

end  

close pcurr  



return @Str 

END 



GO

 

你可能感兴趣的:(sql)