title: How to create Cursor for Insert in Sybase
body: <p>I have the below query that inserts data into a table. The issue is that there are a lot of records and it fills up the transaction log in the database. So, I need to either do the insert in batches or use a cursor. Anyone has idea how the below query can be re-structured to work using a cursor?</p>
  
  <pre><code>SELECT 
      h.issue_id,
      h.account_id,
      h.shares_held,
      h.shares_change,
      a.current_report_date
  INTO #tmp_holding    
  FROM edgar_holding h
  JOIN edgar_account a ON h.account_id = a.account_id
  
  INSERT INTO edgar_holding_hist
  SELECT
      h.issue_id,
      h.account_id,
      h.shares_held,
      h.shares_change,
      h.current_report_date
  FROM #tmp_holding h
  LEFT JOIN edgar_holding_hist hh 
  ON hh.account_id = h.account_id
  AND hh.issue_id = h.issue_id
  AND hh.current_report_date = h.current_report_date
  WHERE hh.issue_id IS NULL
  OR hh.account_id IS NULL
  OR hh.current_report_date IS NULL
  
  DROP TABLE #tmp_holding 
  </code></pre>