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
 declaring cursor variable in sql

Author  Topic 

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-06-21 : 07:52:00
I have a cursor

say like

declare

Cursor c1 for select col1,col2,col3..coln from tab;

-- now I want to declare cursor variable
-- some thing like cur_var c1%rowtype of oracle
-- instead of declaring individual column and then using in the loop



Regards,


-Neil

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-21 : 08:22:05
What are you trying to do with the cursor?

Madhivanan

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

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-06-21 : 08:28:25
some calculating in loop using each records value in a cursor.

I am working on converting oracle code to sql


-Neil
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-21 : 08:31:02
quote:
Originally posted by aakcse

some calculating in loop using each records value in a cursor.

I am working on converting oracle code to sql


-Neil


Post some sample data with expected result
In Oracle, you need to use cursor for most of the times. It is not needed in SQL Server

Madhivanan

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

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-06-21 : 09:05:58
A cursor is declared as below
--oracle

cursor c1 is select
--big list of columns
col1...coln
from table
where
..
..
group by
..
..
cur_var C%ROWTYPE;

open c1;
LOOP

fetch c1 into cur_var;
EXIT when c1%NOTFOUND;

--lot of processing is done here, which I have converted in to sql
--4 leangthy if block etc

end loop;
close pos_cursor;



I just need to convert the declaring opening & closing of cursor.

Regards

-Neil
Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-06-21 : 09:13:35
It is a one time job to run this proc, is it is slow in performance it is ok.

-Neil
Go to Top of Page
   

- Advertisement -