Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my cursor

SQL
 declare @product1 CURSOR 

 SET @product1 = CURSOR for SELECT Id from Tbl_StkDetailedBookStock where IsActive='True'         
 and  BookStockId=@tempd4 ;
here I have 2 records in cursor (SELECT Id from Tbl_StkDetailedBookStock where IsActive = 'True' and BookStockId = 11)


So how to find cursor count = 2 because I want find the cursor count and do some operation based on that count.

anybody help to find this.

thanks.
Posted
Updated 26-May-13 20:30pm
v2
Comments
Maciej Los 27-May-13 2:32am    
Not clear... Please, be more specific and provide more details (example data, expected output).
Basmeh Awad 27-May-13 3:44am    
i have tried but..i think incrementing a daclared variable would be good in your loop..anyway go through the link in solution

Hi,

try this,

declare @product1 CURSOR
 declare @ID int
 declare @cnt int;
set @cnt = 0;

SET @product1 = CURSOR for SELECT Id from Tbl_StkDetailedBookStock where IsActive='True'
and  BookStockId=@tempd4 ;

open   @product1

fetch next from @product into @ID
while(@@fetch_status=0)
begin
set @cnt=@cnt+1
fetch next from @product into @ID
end
close @product1
deallocate @product1

select @cnt




hope it will help....
Happy coding.. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900