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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Cursor with Parameter like in PL/SQL

Author  Topic 

joewe
Starting Member

4 Posts

Posted - 2004-05-25 : 09:04:19
is it possible to implement a cursor with a parameter in T-SQL like in PL/SQL?

[Example-Start]
CURSOR c_tmp (nr INTEGER) is
SELECT
ROWID
, DATA01
, DATA02
WHERE
DATANUMBER = nr
;

BEGIN
...
OPEN c_tmp(20);
LOOP
FETCH c_tmp INTO row, v01, vo2;
...
END LOOP;
END;
[Example-End]

What would be an equivalent solution in T-SQL.
The special problem for me is, that both solutions should look alike because our software has to run on Oracle or MS SQL-Server.
Therefore we would like the code not to differ to much for each DB?

Thanks for your solutions
Jörg

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-05-25 : 09:36:24
What are you trying to accomplish with your cursor?
Many members of this forum may be able to help you re-write it without using a cursor..
Go to Top of Page

joewe
Starting Member

4 Posts

Posted - 2004-05-25 : 09:43:00
Hi enhorn,

i have to read each single Dataset in the loop an then there are several steps that also manipulate Data from other tables.
It's not possible to do it by one large select- or update-statement.

Let's say it like this:
I have a loop that reads data (could be a cursor or ???) and the data are processed in the loop.

The cursor has got the parameter because it is needed at several places in my procedure with different parameters.
Maybe this example isn't clear becuase you don't see the context (it's an easy example, my real cursor look different).
But i think the whole SQL-Procedure would be to much.

jörg
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-05-25 : 10:06:00
give us some sample data and what you need to accomplish and I guarantee we'll be able to take your long T-SQL Cursor code and code it is as a simple series of set-based operations. Give us some relavant table definitions and just enough sample data for you to show us what you need to do.

This is a great opportunity for you to learn about the power of set-based processing and to learn to NOT use cursors!

- Jeff

- Jeff
Go to Top of Page

joewe
Starting Member

4 Posts

Posted - 2004-05-26 : 01:03:04
Hi Jeff,
sounds good, i'm curious.
PL/SQL is no problem for me. But it's the classical problem. if you know a solution in one language you want to do the same in the other language. T-SQL is new to me, so i have to learn. Thank you very much for your help.
I'll send you an Email. But i need a little time to prepare the data.

jörg
Go to Top of Page

joewe
Starting Member

4 Posts

Posted - 2004-05-28 : 04:48:50
Sorry, at the moment, i have to few time for preparing the data and the procedure.
But in general: is it possible in T-SQl to have a cursor with a parameter like in PL/SQL? (see example above)
Go to Top of Page
   

- Advertisement -