Cursors

Posted by: cadarsh89

Tagged in: Untagged 

create table  t1 (id int, name varchar(10))
insert into t1 values (1,'adarsh')
insert into t1 values (2,'vinod')
insert into t1 values (3,'Rahul')
insert into t1 values (4,'Rohit')
insert into t1 values (5,'Sanjeev')

declare @name varchar(100)
declare c1 cursor read_only for select name from t1
open c1 fetch next from c1 into @name

while @@fetch_status = 0 begin print @name
fetch next from c1 into @name end
close c1
deallocate c1
--Result:adarsh
--vinod
--Rahul
--Rohit
--Sanjeev
xp_logininfo grant all on t1 to customer1