March 26, 2004 at 7:43 am
I have a table : MyTable (id, name)
I have a procedure fgirtest which is :
CREATE PROCEDURE fgirtest (@titles_cursor CURSOR VARYING OUTPUT) AS
SET @titles_cursor = CURSOR FOR SELECT * FROM chain
RETURN
GO
Then in another procedure, i want to do this :
DECLARE @MyCursor CURSOR, @name VARCHAR
EXEC fgirtest @MyCursor OUTPUT
WHILE (@@FETCH_STATUS = 0)
BEGIN
FETCH NEXT FROM @MyCursor INTO @name
INSERT INTO MyTable(name) VALUES(@name)
END
And nothing is done ... What can i do ? Is it possible ?
thks,
March 26, 2004 at 7:52 am
Do you have any records in the chain table?
Does it have only a column named name?
You coud add prints inside the sp to know the values of variables.
March 26, 2004 at 7:59 am
That won't work. See http://www.sommarskog.se/dynamic_sql.html#cursor how to declare dynamically a cursor.
But more important: Why do you use a cursor anyway?
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
March 26, 2004 at 8:00 am
of course, i have a field "name" in my table "chain" ....
March 26, 2004 at 8:05 am
So what?
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
March 26, 2004 at 8:22 am
I use a cursor, because I want to create a system of rules based on stored procedure which allows to the user to create him self stored procedures with existing procedure ...
So, in some case i need that a stored procedure returns a cursor ...
Is it clear ?
March 26, 2004 at 8:22 am
What is the ultimate goal here for your data? May be the wrong approach.
March 26, 2004 at 9:15 am
Hi GIRODON,
I don't know if you have already taken a look at BOL, but if not please take a look at Example given under
stored procedures, CURSOR_STATUS
It will give a pretty good idea about the VARYING OUTPUT CURSOR.
Thanks
Prasad Bhogadi
www.inforaise.com
March 26, 2004 at 9:42 am
I've found !
CREATE PROCEDURE fgirtest(@my_cursor CURSOR VARYING OUTPUT)
AS
SET @my_cursor = CURSOR STATIC FOR SELECT name FROM chain
OPEN @my_cursor
RETURN
GO
DECLARE @MyCursor CURSOR
DECLARE @name VARCHAR(250)
EXEC fgirtest @MyCursor OUTPUT
FETCH NEXT FROM @MyCursor INTO @name
WHILE (@@FETCH_STATUS = 0)
BEGIN
INSERT into test(name) VALUES(@name)
FETCH NEXT FROM @MyCursor INTO @name
END
Viewing 9 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply