title: fetch record from cursor in SQL
body: <p>i have list of records and have created cursor to loop through each record and check certain condition and return record if it satisfies my cursor is as follows :</p>
  
  <pre><code>DECLARE @ID int
  DECLARE @FromDate datetime, @ToDate datetime
  DEClare @expid as int
  set @expid = 839
  DECLARE IDs CURSOR FOR 
  select patpid,fromdate,todate from tdp_ProviderAccomodationTariffPlan where fk_patid =    162 and fk_pacid = 36
  
   OPEN IDs
   FETCH NEXT FROM IDs into @ID,@FromDate,@ToDate
   WHILE @@FETCH_STATUS = 0
   BEGIN
  print @ID 
  print @FromDate
  print @ToDate
  
  --SELECT patpid,rate,SType FROM tdp_ProviderAccomodationTariffPlan 
  --WHERE ('2012-12-27' BETWEEN @FromDate AND @ToDate) and fk_patid = 162 and fk_pacid = 36
  
  FETCH NEXT FROM IDs into @ID,@FromDate,@ToDate  
  
  END
  CLOSE IDs
  DEALLOCATE IDs
  </code></pre>
  
  <p>in loop cursor fetch record whose id is '839' , Please help me solve the problem.</p>