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 %>
  <pre>
  DECLARE <% = Request.Form("cursorName") %> CURSOR LOCAL FORWARD_ONLY
  READ_ONLY FOR
  -- Add SQL.

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

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

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


[Return to the tip]