Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to display results from a cursor

Author  Topic 

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-02-16 : 10:05:14
Can you plz help me in priting the values received from a cursor,
the cursor select stm has a big list, I want to display the cursor results for the below proc.

Regards,
aak



CREATE PROCEDURE dbo.uspCurrencyCursor
@CurrencyCursor CURSOR VARYING OUTPUT
AS
SET NOCOUNT ON;
SET @CurrencyCursor = CURSOR
FORWARD_ONLY STATIC FOR
SELECT CurrencyCode, Name, .......
FROM Sales.Currency;
OPEN @CurrencyCursor;
GO

DECLARE @MyCursor CURSOR;
EXEC dbo.uspCurrencyCursor @CurrencyCursor = @MyCursor OUTPUT;
WHILE (@@FETCH_STATUS = 0)
BEGIN;
FETCH NEXT FROM @MyCursor; --here I want to print the records ---fetch by the cursor
END;
CLOSE @MyCursor;
DEALLOCATE @MyCursor;

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-02-16 : 10:06:49
And the reason you are using a cursor for this?
Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-02-16 : 10:20:42
Actually I have a situation where the out parameter is cursor in a SProc with 2 in parameter
a select query returns result set, which I want to catch and display.

( I am trying to implement a ref cursor(of oralce) in sqlserver ) I got it rightly but I am not aware of how to display the result and see.

I am able to catch but not display as above.

Regards,
aak
Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-02-16 : 10:36:08
[code]
DECLARE @MyCursor CURSOR;
declare a@ varchar(1000),@b varchar(1000)
EXEC dbo.uspCurrencyCursor @CurrencyCursor = @MyCursor OUTPUT;
WHILE (@@FETCH_STATUS = 0)
BEGIN;
FETCH NEXT FROM @MyCursor into @a,@b...; --here I want to print the records ---fetch by the cursor
PRINT @a + @b ..-- I tried taking all the values in the cur into a variable and then print it executing but not printing?
END;

CLOSE @MyCursor;
DEALLOCATE @MyCursor;
[/code]
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-02-16 : 11:04:09
quote:
Originally posted by aakcse
I want to display the cursor results for the below proc.



k


SELECT CurrencyCode, Name, ....... FROM Sales.Currency;


Next!



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-17 : 01:48:12
<<
I am trying to implement a ref cursor(of oralce) in sqlserver
>>

In ORACLE you need cursor. In SQL Server you dont need for this case


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-17 : 01:51:33
quote:
Originally posted by madhivanan

<<
I am trying to implement a ref cursor(of oralce) in sqlserver
>>

In ORACLE you need cursor. In SQL Server you dont need for this case


Madhivanan

Failing to plan is Planning to fail


Wow! Another instance of 'ORACLE effect'

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-17 : 01:57:10
quote:
Originally posted by visakh16

quote:
Originally posted by madhivanan

<<
I am trying to implement a ref cursor(of oralce) in sqlserver
>>

In ORACLE you need cursor. In SQL Server you dont need for this case


Madhivanan

Failing to plan is Planning to fail


Wow! Another instance of 'ORACLE effect'

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




Yes

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -