title: Sql Server - Cursor not working in stored procedure
body: <p>I'm using AdventureWorks ( Sql server 2005 express) and want to find out if which gender has highes leave hours with the following SP.
  The SP compiles well but is not showing any result on execution</p>
  
  <p>here is the sp </p>
  
  <pre><code>create proc GenderLeaveCount
  as
  begin
  declare @gender nchar(1)
  declare @leaveHours smallint
  
  declare @totalHoursMale int
  declare @totalHoursFemale int
  
  declare genderLeave Cursor
  for select Gender , SickLeaveHours
  from HumanResources.Employee
  where SickLeaveHours is not null and Gender is not null
  
  
  open genderLeave
  
  fetch next from genderLeave 
  into @gender,@leaveHours
  
  while @@fetch_status=0
  Begin
      IF @gender = N'M'
          Set @totalHoursMale = @totalHoursMale + @leaveHours
      ELSE
          Set @totalHoursFemale = @totalHoursFemale + @leaveHours
  
      fetch next from genderLeave 
      into @gender,@leaveHours
  
  End
  
  close genderLeave
  deallocate genderLeave
  
  IF @totalHoursMale &gt; @totalHoursFemale
      Select 'Male leave hours are higher:' + cast(@totalHoursMale as varchar(20))as result
  IF @totalHoursMale &lt; @totalHoursFemale
      Select 'Male leave hours are higher:' + cast(@totalHoursMale as varchar(20))as result
  IF @totalHoursMale = @totalHoursFemale
      Select 'Male leave hours are higher:' + cast(@totalHoursMale as varchar(20)) as result
  
  end
  go
  exec GenderLeaveCount
  </code></pre>
  
  <hr>
  
  <p>Can anyone please let me know what the issue is and how to fix it..</p>