A Single-Column Traversing Cursor Code Generating Script Demo

This demo illustrates how to automatically have the code for a single-column traversing cursor be generated. Specify the name of the cursor and the name of the variable you wish to store the column of the current row in. Submitting the page automatically generates the shell of the cursor code - all you need to do is add the SQL query to populate the cursor and the code to work with the currently selected row!

Cursor Name:      Var Name:     

Source Code:
' Helpful script for rendering SQL to do CURSOR work.

<% if Request.Form.Count > 0 then %>
  DECLARE <% = Request.Form("cursorName") %> CURSOR LOCAL FORWARD_ONLY
  -- Add SQL.

  OPEN <% = Request.Form("cursorName") %>
  DECLARE @<% = Request.Form("varName") %> int
  FETCH NEXT FROM <%=Request.Form("cursorName")%> INTO @<%=Request.Form("varName")%>
    -- Add code.
    FETCH NEXT FROM <%=Request.Form("cursorName")%> INTO @<%=Request.Form("varName")%>

  CLOSE <% = Request.Form("cursorName") %>
  DEALLOCATE <% = Request.Form("cursorName") %>
<% end if %>

<form method=post>
  Cursor Name:
  <input name=cursorName value="<% = Request.Form("cursorName") %>">
  Var Name:
  <input name=varName value="<% = Request.Form("varName") %>">
  <input type=submit>

[Return to the tip]