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.
| Author |
Topic |
|
SQLboom
Yak Posting Veteran
63 Posts |
Posted - 2004-02-19 : 08:04:41
|
| i had been trying for a conversion from Oracle's parameterized cursor to SQL Server's simple one.. . .although the BOL says that the cursor fetches data when it is "opened".....why the following doesn't happen.. . .declare @par int, @out1 varchar(1)set @par = 0--declare mycur cursor for select 'A', 'B', 'C' where 1 = @par--open mycur -- NOW HERE THE CURSOR should open with @par = 0fetch next from mycur into @out1print @out1 -- THIS SHOULD BE "NULL" AND IT DOES COME NULLclose mycur--set @par = 1open mycur -- NOW HERE THE CURSOR should open with @par = 1 [as per BOL]fetch next from mycur into @out1print @out1 -- THIS SHOULD BE "A" AND IT COMES NULLclose mycur--If the second case doesn't happen, then what really is the purpose of opening and closing a cursor...Thanks. |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-02-19 : 08:25:13
|
| Not much purpose really, and you should not be using cursors anyway. In this case, the cursor fetches data when it is opened, but it will only fetch the data that meets the conditions of the cursor declaration. You declared the cursor with a value of zero, that will not change until it is redeclared.Row-by-row processing with cursors is incredibly inefficient, and you should not use them at all. What works in Oracle will not work the same in SQL Server. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-02-19 : 08:28:01
|
| >> then what really is the purpose of opening and closing a cursor...Good question.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|