Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UDF - Cursor return -1 for rowcount
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00897180
Message ID:
00897183
Views:
18
This message has been marked as the solution to the initial question of the thread.
You should be able to achieve the same results with this:

Declare @returnValue varchar(1000)
set @returnValue = ''
select @returnValue = @returnValue + rtrim(Description)
from meetings mx inner join
meetproc mp on mp.meetingnumber=mx.meetingnumber
where mx.meetingNumber = @tiMeetID
order by mp.sysorder

As for your cursor method, it's more common to use @@fetch_status as a signal to end the loop instead of relying on @@cursor_rows.

-Mike

>I'm wondering if anyone can spot a problem in my code. I'm trying to create a function that returns a string value that is based on one field from the query inside the udf. Running the the actual query by itself works, but in the UDF, the cursor is showing -1 for the @@cursor_rows value. The BOL say that if it returns a -1 the cursor is dynamic, but I don't know what would make this dynamic. Thanks for any help.
>
>Kirk
>
>
>
>CREATE FUNCTION Get_ProceduresOnCase  (@tiMeetID int)
>RETURNS varchar(1000) AS
>BEGIN
>     declare @tcProcDesc varchar(200)
>     Declare @returnValue varchar(1000)
>     declare @tiRows int
>     declare @tiCtr int
>     set @tiCtr=1
>     declare CaseProcs cursor local for
>	   select rtrim(Description)
>		from meetings mx inner join
>                     meetproc mp on mp.meetingnumber=mx.meetingnumber
>	where mx.meetingNumber = @tiMeetID
>	order by mp.sysorder
>	-- Open our cursor and determine how many rows are in it
>	Open CaseProcs
>	set @tiRows=@@cursor_rows
>
>	-- Loop Through the Cursor
>	while (@tiCtr <= @tiRows)
>	Begin
>	   fetch CaseProcs into @tcProcDesc
>           set @returnValue=@returnValue+rtrim(@tcProcDesc)+', '
>	end
>     -- Close the Cursor
>     Close CaseProcs
>     DeAllocate CaseProcs
>     return (@returnValue)
>END
>
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform