SQL Server 2008R2 Custom Function so slow -


here function:

-- declare @cur cursor declare @line int declare @return varchar(255)  declare mycursor cursor select distinct (quote_ln_no) quote_ln_no   dbo.quote_line_bom  quote_no = @quote_no , component_mat_no = @mat_no order quote_ln_no  set @return = ''  open mycursor  fetch next mycursor @line while @@fetch_status = 0 begin   set @return = @return + convert(varchar, @line) + ', '   fetch next mycursor    @line end  close mycursor deallocate mycursor   if len(@return) > 0  set @return = substring(@return, 1, len(@return)-1)  return @return 

when use function in query returns on 3000 records, function adds 20 seconds.

please let me know wrong or there way make run faster?

i think faster. it's set-based , doesn't use cursor.

declare @return varchar(255) = ''  select @return = @return + cast(quote_ln_no varchar) + ',' dbo.quote_line_bom quote_no = @quote_no , component_mat_no = @mat_no , quote_ln_no not null group quote_ln_no order quote_ln_no  if len(@return) > 0      set @return = substring(@return, 1, len(@return)-1)  select @return  --this user defined function, right? --return @return 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -