T-SQL gurus, what is causing the following procedure to return this error "Select statements included within a function cannot return data to a client."?
create function dbo.func_get_times_for_stop(@stopId as varchar(5))
returns varchar(max) as
begin
declare @arrival_times varchar(max)
set @arrival_times = '';
declare @arrival_time varchar(5)
declare arrival_cursor cursor for
select arrival from schedules where stopid=@stopId;
open arrival_cursor;
fetch next from arrival_cursor;
while @@fetch_status = 0
begin
fetch next from arrival_cursor into @arrival_time;
set @arrival_times += ',' + @arrival_time;
end;
close arrival_cursor;
deallocate arrival_cursor;
return @arrival_times;
end;
I am simply trying to return a scalar which comprises the string concatenated from arrival times. I do not see where I am returning a select statement.