M
Michael
Hi all..
I have a stored procedure that needs to return a record from one of two
tables. I'm using an outpur parameter of type cursor. In the proc, I test if
the record exists in table 1, if so, retrieve and store in the output.
Otherwise retrieve the record from Table 2 and store in the output.
The problem is that there is no parameter type in ADO.Net to hold the
returned cursor. I tried using SqlCommandBuilder.DeriveParameters, and it
says the output param is of type int, which confuses me.
It's probably something simple, I hope..
Here's the stored proc..
CREATE PROCEDURE RetrieveRecord (@rec_id varchar(50), @ret_cur CURSOR
VARYING OUTPUT)
AS
DECLARE @exists bit
SELECT @exists = CASE WHEN COUNT(rec_pk) > 0 THEN 1 ELSE 0 END
FROM Table1 WHERE rec_pk = @rec_id
IF @exists = 1
BEGIN
DECLARE cur1 CURSOR LOCAL READ_ONLY FOR
SELECT rec_pk, description, status, submit_date
FROM Table1 WHERE rec_pk = @rec_id
OPEN cur1
SET @ret_cur = cur1
END
ELSE
DECLARE cur1 CURSOR LOCAL READ_ONLY FOR
SELECT rec_pk, description, status, submit_date
FROM Table2 WHERE rec_pk = @rec_id
OPEN cur1
SET @ret_cur = cur1
GO
I have a stored procedure that needs to return a record from one of two
tables. I'm using an outpur parameter of type cursor. In the proc, I test if
the record exists in table 1, if so, retrieve and store in the output.
Otherwise retrieve the record from Table 2 and store in the output.
The problem is that there is no parameter type in ADO.Net to hold the
returned cursor. I tried using SqlCommandBuilder.DeriveParameters, and it
says the output param is of type int, which confuses me.
It's probably something simple, I hope..
Here's the stored proc..
CREATE PROCEDURE RetrieveRecord (@rec_id varchar(50), @ret_cur CURSOR
VARYING OUTPUT)
AS
DECLARE @exists bit
SELECT @exists = CASE WHEN COUNT(rec_pk) > 0 THEN 1 ELSE 0 END
FROM Table1 WHERE rec_pk = @rec_id
IF @exists = 1
BEGIN
DECLARE cur1 CURSOR LOCAL READ_ONLY FOR
SELECT rec_pk, description, status, submit_date
FROM Table1 WHERE rec_pk = @rec_id
OPEN cur1
SET @ret_cur = cur1
END
ELSE
DECLARE cur1 CURSOR LOCAL READ_ONLY FOR
SELECT rec_pk, description, status, submit_date
FROM Table2 WHERE rec_pk = @rec_id
OPEN cur1
SET @ret_cur = cur1
GO