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 likeSELECT SUM( CASE WHEN status='present' THEN 1 ELSE 0 END ) AS PresentCount,SUM( CASE WHEN status='absent' THEN 1 ELSE 0 END ) AS AbsentCountFROM kkk |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-02-08 : 13:52:12
|
Or this:SELECTstatus,count(*) as counterfrom kkkgroup by statusSo 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. |
|
|
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 likeSELECT SUM( CASE WHEN status='present' THEN 1 ELSE 0 END ) AS PresentCount,SUM( CASE WHEN status='absent' THEN 1 ELSE 0 END ) AS AbsentCountFROM kkk
hello friend,i am new to cursors concept in sqlserver..i need to know about cursors..if you can help me friend... |
|
|
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 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-10 : 08:18:42
|
Are you also studying ORACLE as part of the syllabus? MadhivananFailing to plan is Planning to fail |
|
|
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? MadhivananFailing to plan is Planning to fail
May be he's trying to compare cursors in MS SQL vs ORACLE------------------------------------------------------------------------------------------------------SQL Server MVP |
|
|
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 Athalyehttp://www.letsgeek.net/ |
|
|
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. |
|
|
|