How to use cursor
hi friends i need to know about cursors in sqlserver....i have a table called "kkk" with a column "status"...two values "present" and "absent" represents the column "status"...i want to count how many values represent "present" and "status"..i want this task to be done using cursors...i am very new to sqlserver....any other method is also appreciated....help me friends....

Bryian TanRank #396 · 6.3K reputationPosted Feb 8, 2010, 6:41 AM EST
try this example http://blog.ysatech.com/post/2009/08/02/SQL-2005-Cursor-Template.aspx
Thanks,
Bryian Tan
kiran kumarRank #3,110 · 461 reputationPosted Feb 8, 2010, 6:48 AM EST
Bryian TanRank #396 · 6.3K reputationPosted Feb 8, 2010, 9:32 AM EST
Can you post the tSql you have now and I can look into it.
Thanks,
Bryian Tan
Kirtan PatelRank #292 · 8.6K reputationPosted Feb 8, 2010, 4:42 PM EST
declare @total_absent numeric(5) declare @total_present numeric(5) declare @status varchar(50) declare c1 cursor for select * from kkk set @total_absent =0 set @total_present = 0 Open c1 fetch next from c1 into @status while @@FETCH_STATUS = 0 begin if ( @status = 'present') set @total_absent = @total_absent+1; else set @total_present = @total_present+1; fetch next from c1 into @status end print @total_absent print @total_present close c1 DEALLOCATE c1Mauricio Rosa5 reputationPosted Feb 25, 2010, 8:03 AM EST
I think that you´re only tring to understand how to cursos work in SQL Server, rigth?
How you´re new in SQL Server, it´s important keep in mind that cursors must be used only if have not another way to do what you need to do.
Look using good eyes to temporary tables once SQL Server is optmized to work with them. Used on SQL Server, cursors deprecate the server perfomance in higher levels
Regards