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
 General SQL Server Forums
 New to SQL Server Programming
 cursor in sqlserver

Author  Topic 

kirangentlebreeze1987
Starting Member

14 Posts

Posted - 2010-02-08 : 11:58:01
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....

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-08 : 12:00:40
why should you use cursors. you can simply go for a set based approach like

SELECT SUM( CASE WHEN status='present' THEN 1 ELSE 0 END ) AS PresentCount,
SUM( CASE WHEN status='absent' THEN 1 ELSE 0 END ) AS AbsentCount
FROM kkk
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-02-08 : 13:52:12
Or this:

SELECT
status,
count(*) as counter
from kkk
group by status

So you can see all values of column status and the related counter.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

kirangentlebreeze1987
Starting Member

14 Posts

Posted - 2010-02-08 : 21:15:15
quote:
Originally posted by visakh16

why should you use cursors. you can simply go for a set based approach like

SELECT SUM( CASE WHEN status='present' THEN 1 ELSE 0 END ) AS PresentCount,
SUM( CASE WHEN status='absent' THEN 1 ELSE 0 END ) AS AbsentCount
FROM kkk




hello friend,i am new to cursors concept in sqlserver..i need to know about cursors..if you can help me friend...
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-02-08 : 21:46:47
I don't know why you want to learn cursors, when the examples provided are better, smaller, and more efficient, but if you absolutely must:

http://msdn.microsoft.com/en-us/library/ms180169.aspx
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-10 : 08:18:42
Are you also studying ORACLE as part of the syllabus?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-10 : 08:29:02
quote:
Originally posted by madhivanan

Are you also studying ORACLE as part of the syllabus?

Madhivanan

Failing to plan is Planning to fail


May be he's trying to compare cursors in MS SQL vs ORACLE

------------------------------------------------------------------------------------------------------
SQL Server MVP
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2010-02-10 : 08:37:59
May be he is just curious to know about cursor, but couldn't find a better problem to put forward.

Or may be the assignment specifically asked for using cursors?

Harsh Athalye
http://www.letsgeek.net/
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-02-10 : 11:51:45
Have cursors changed in the last couple of versions of SQL so that they are safer? Meaning, as far as I know, they can still take down the entire server if used improperly.
Go to Top of Page
   

- Advertisement -