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
 SQL Server Development (2000)
 Returning a cursor from a function

Author  Topic 

vin
Starting Member

26 Posts

Posted - 2003-05-16 : 07:54:22
Hi,
In sql server 2000 is it not possible to return a cursor as a resultset.


Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2003-05-16 : 08:00:24
cursor/resultset .... apples/oranges ...

What business rule are you trying to fulfill and what method are you trying to use to do it?

Jay White
{0}
Go to Top of Page

vin
Starting Member

26 Posts

Posted - 2003-05-16 : 08:19:55
Hi White,

Suppose i hava a emp table, i need to select multiple records based on some condition, say sal>1000. How can i return the result set (ie is the multiple records). Can i return in as cursor.

The returned records has to be processed by some other application.



Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2003-05-16 : 08:22:13

create proc emp_with_sal_more_than_one_large
as
select
emp_data
from
emp_table
where
sal > 1000
go

 


Jay White
{0}
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-05-16 : 09:19:56
SQL returns results as a "recordset" of rows/columns using stored procedures or sql statements.

in your application, you use ADO to execute that sql statement or stored procedure, and what is returned back is a cursor to the results. You then use that cursor to process the rows in your application.

i.e.,

dim r as recordset
set r = connection.execute "some sql here"
r.movefirst

' Now r is basically a cursor

do while not r.eof
do something
do something else

r.movenext ' move the cursor to the next row in the results
loop

does that clear things up a little? you only declare a cursor in SQL if you need SQL Server to process 1 row at a time in a result set, which you almost never need to do since SQL deals very efficiently with SETS of rows all at once.


- Jeff
Go to Top of Page

vin
Starting Member

26 Posts

Posted - 2003-05-17 : 02:09:20
Thanx Jeff...
It is clear now

Go to Top of Page
   

- Advertisement -