{"id":84,"date":"2008-09-24T15:05:43","date_gmt":"2008-09-24T14:05:43","guid":{"rendered":"http:\/\/www.tsls.co.uk\/?p=84"},"modified":"2026-03-11T10:44:08","modified_gmt":"2026-03-11T10:44:08","slug":"asp-nested-loop-doing-the-loop","status":"publish","type":"post","link":"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/","title":{"rendered":"ASP SQL Nested Loop doing the Loop"},"content":{"rendered":"<p>Nesting the loop, Important thing to note make sure that you use recordset<\/p>\n<p>\u00a0<\/p>\n<p>&lt;%@ LANGUAGE=&#8221;VBSCRIPT&#8221; %&gt;<br \/>\n&lt;% response.cachecontrol = &#8220;Public&#8221; %&gt;<br \/>\n&lt;%Response.Buffer = False%&gt;<\/p>\n<p>&lt;HTML&gt;<br \/>\n&lt;HEAD&gt;<br \/>\n&lt;TITLE&gt;Title&lt;\/TITLE&gt;<br \/>\n&lt;\/HEAD&gt;<\/p>\n<p>&lt;%<br \/>\nSet conn= Server.CreateObject(&#8220;ADODB.Connection&#8221;)<br \/>\nconn.ConnectionTimeout = Session(&#8220;Support_ConnectionTimeout&#8221;)<br \/>\nconn.CommandTimeout = Session(&#8220;Support_CommandTimeout&#8221;)<br \/>\nconn.Open Session(&#8220;Support_ConnectionString&#8221;), Session(&#8220;Support_RuntimeUserName&#8221;), Session(&#8220;Support_RuntimePassword&#8221;)<br \/>\nSet cmdTemp = Server.CreateObject(&#8220;ADODB.Command&#8221;)<br \/>\nSet rs1 = Server.CreateObject(&#8220;ADODB.Recordset&#8221;)<br \/>\ncmdTemp.CommandText = &#8220;exec sp&#8221;<br \/>\ncmdTemp.CommandType = 1<br \/>\nSet cmdTemp.ActiveConnection = conn<br \/>\nrs1.Open cmdTemp, , 0, 1<br \/>\n%&gt;<\/p>\n<p>\u00a0<\/p>\n<p>&lt;% If Not rs1.EOF Or Not rs2.BOF Then %&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&#8230;&#8230;&#8230;..First Stuff&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n<p>&lt;%dim CurrentContract%&gt;<br \/>\n&lt;%CurrentContract = 0%&gt;<\/p>\n<p>\u00a0&lt;% do While NOT adoOpenCalls.EOF %&gt;<br \/>\n\ufffd<br \/>\n\u00a0\u00a0&lt;%CurrentContract = adoOpenCalls(&#8220;con_id&#8221;).value%&gt;<\/p>\n<p>\u00a0\u00a0&#8230;&#8230;&#8230;&#8230;1st Loop STUFF&#8230;&#8230;&#8230;<br \/>\n\u00a0\ufffd<br \/>\n\u00a0\u00a0\u00a0\u00a0&lt;%count = 0%&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0&lt;%<br \/>\n\u00a0\u00a0\u00a0\u00a0Set rs1= Server.CreateObject(&#8220;ADODB.Recordset&#8221;)<br \/>\n\u00a0\u00a0\u00a0\u00a0cmdTemp.CommandText = &#8220;exec sp&#8221; &amp; CurrentContract\ufffd<br \/>\n\u00a0\u00a0\u00a0\u00a0cmdTemp.CommandType = 1<br \/>\n\u00a0\u00a0\u00a0\u00a0Set cmdTemp.ActiveConnection = conn<br \/>\n\u00a0\u00a0\u00a0\u00a0adoLoopIncidents.Open cmdTemp, , 0, 1\u00a0\u00a0\ufffd<br \/>\n\u00a0\u00a0\u00a0\u00a0%&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\ufffd<br \/>\n\u00a0\u00a0\u00a0\u00a0\ufffd<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0&lt;%<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0Do while not adoLoopIncidents.eof<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0count = count + 1<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0%&gt;<br \/>\n\u00a0\u00a0\u00a0\ufffd<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0&#8230;&#8230;&#8230;&#8230;2nd Loop STUFF&#8230;&#8230;&#8230;<br \/>\n\u00a0\u00a0\u00a0\u00a0\ufffd<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0&lt;%adoLoopIncidents.movenext%&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0&lt;%loop%&gt;<\/p>\n<p>\u00a0\u00a0&#8230;&#8230;&#8230;&#8230;.Stuff at end of loop&#8230;&#8230;&#8230;..<\/p>\n<p>\u00a0\u00a0&lt;% adoOpenCalls.movenext %&gt;<br \/>\n\u00a0\u00a0&lt;%loop%&gt;<br \/>\n&lt;%else%&gt;<br \/>\n&#8230;&#8230;..else stuff&#8230;&#8230;&#8230;<br \/>\n&lt;%end if%&gt;<\/p>\n<p>&#8230;&#8230;..Last Stuff&#8230;&#8230;&#8230;<\/p>\n<p>&lt;%<br \/>\nadoOpenCalls.Close<br \/>\nSet adoOpenCalls = Nothing<br \/>\n%&gt;<\/p>\n<p>&lt;\/BODY&gt;<br \/>\n&lt;\/HTML&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nesting the loop, Important thing to note make sure that you use recordset \u00a0 &lt;%@ LANGUAGE=&#8221;VBSCRIPT&#8221; %&gt; &lt;% response.cachecontrol = &#8220;Public&#8221; %&gt; &lt;%Response.Buffer = False%&gt; &lt;HTML&gt; &lt;HEAD&gt; &lt;TITLE&gt;Title&lt;\/TITLE&gt; &lt;\/HEAD&gt; &lt;% Set conn= Server.CreateObject(&#8220;ADODB.Connection&#8221;) conn.ConnectionTimeout =<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[21],"tags":[311,651,1131,2081,2341],"class_list":["post-84","post","type-post","status-publish","format-standard","hentry","category-microsoft","tag-asp","tag-do","tag-loop","tag-sql","tag-while"],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>ASP SQL Nested Loop doing the Loop - TSLS - Luke Smith<\/title>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_GB\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"ASP SQL Nested Loop doing the Loop - TSLS - Luke Smith\" \/>\r\n<meta property=\"og:description\" content=\"Nesting the loop, Important thing to note make sure that you use recordset \u00a0 &lt;%@ LANGUAGE=&#8221;VBSCRIPT&#8221; %&gt; &lt;% response.cachecontrol = &#8220;Public&#8221; %&gt; &lt;%Response.Buffer = False%&gt; &lt;HTML&gt; &lt;HEAD&gt; &lt;TITLE&gt;Title&lt;\/TITLE&gt; &lt;\/HEAD&gt; &lt;% Set conn= Server.CreateObject(&#8220;ADODB.Connection&#8221;) conn.ConnectionTimeout =\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/\" \/>\r\n<meta property=\"og:site_name\" content=\"TSLS - Luke Smith\" \/>\r\n<meta property=\"article:published_time\" content=\"2008-09-24T14:05:43+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2026-03-11T10:44:08+00:00\" \/>\r\n<meta name=\"author\" content=\"Luke Smith\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Luke Smith\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/\",\"url\":\"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/\",\"name\":\"ASP SQL Nested Loop doing the Loop - TSLS - Luke Smith\",\"isPartOf\":{\"@id\":\"https:\/\/www.tsls.co.uk\/#website\"},\"datePublished\":\"2008-09-24T14:05:43+00:00\",\"dateModified\":\"2026-03-11T10:44:08+00:00\",\"author\":{\"@id\":\"https:\/\/www.tsls.co.uk\/#\/schema\/person\/e4d7dac4fe1b3f8df31f3857bb3ebda7\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.tsls.co.uk\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ASP SQL Nested Loop doing the Loop\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.tsls.co.uk\/#website\",\"url\":\"https:\/\/www.tsls.co.uk\/\",\"name\":\"TSLS - Luke Smith\",\"description\":\"- Knowledge - Thoughts - Microsoft -\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.tsls.co.uk\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.tsls.co.uk\/#\/schema\/person\/e4d7dac4fe1b3f8df31f3857bb3ebda7\",\"name\":\"Luke Smith\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.tsls.co.uk\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/29abc50f07a4ebe68cb4f31981884f89b2157d7e4ed63b09631d40c0717faa94?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/29abc50f07a4ebe68cb4f31981884f89b2157d7e4ed63b09631d40c0717faa94?s=96&d=mm&r=g\",\"caption\":\"Luke Smith\"},\"description\":\"I\u2019ve been working with Microsoft Technologies for over 20 years, my main focus now being Microsoft Online Services. I manage the Cloud Services at ElysianIT Limited and as a P-SELLER at Microsoft. I have worked with many organisations from SMC to Enterprise. I\u2019ve been working with Microsoft Technologies since DOS 5.0, to date I have been working on Microsoft\u2019s latest cloud technology Windows Azure, Windows 10 Office 365 and Microsoft SharePoint\",\"sameAs\":[\"http:\/\/www.tsls.co.uk\"],\"url\":\"https:\/\/www.tsls.co.uk\/index.php\/author\/luke\/\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ASP SQL Nested Loop doing the Loop - TSLS - Luke Smith","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/","og_locale":"en_GB","og_type":"article","og_title":"ASP SQL Nested Loop doing the Loop - TSLS - Luke Smith","og_description":"Nesting the loop, Important thing to note make sure that you use recordset \u00a0 &lt;%@ LANGUAGE=&#8221;VBSCRIPT&#8221; %&gt; &lt;% response.cachecontrol = &#8220;Public&#8221; %&gt; &lt;%Response.Buffer = False%&gt; &lt;HTML&gt; &lt;HEAD&gt; &lt;TITLE&gt;Title&lt;\/TITLE&gt; &lt;\/HEAD&gt; &lt;% Set conn= Server.CreateObject(&#8220;ADODB.Connection&#8221;) conn.ConnectionTimeout =","og_url":"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/","og_site_name":"TSLS - Luke Smith","article_published_time":"2008-09-24T14:05:43+00:00","article_modified_time":"2026-03-11T10:44:08+00:00","author":"Luke Smith","twitter_misc":{"Written by":"Luke Smith","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/","url":"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/","name":"ASP SQL Nested Loop doing the Loop - TSLS - Luke Smith","isPartOf":{"@id":"https:\/\/www.tsls.co.uk\/#website"},"datePublished":"2008-09-24T14:05:43+00:00","dateModified":"2026-03-11T10:44:08+00:00","author":{"@id":"https:\/\/www.tsls.co.uk\/#\/schema\/person\/e4d7dac4fe1b3f8df31f3857bb3ebda7"},"breadcrumb":{"@id":"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.tsls.co.uk\/index.php\/2008\/09\/24\/asp-nested-loop-doing-the-loop\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.tsls.co.uk\/"},{"@type":"ListItem","position":2,"name":"ASP SQL Nested Loop doing the Loop"}]},{"@type":"WebSite","@id":"https:\/\/www.tsls.co.uk\/#website","url":"https:\/\/www.tsls.co.uk\/","name":"TSLS - Luke Smith","description":"- Knowledge - Thoughts - Microsoft -","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.tsls.co.uk\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.tsls.co.uk\/#\/schema\/person\/e4d7dac4fe1b3f8df31f3857bb3ebda7","name":"Luke Smith","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.tsls.co.uk\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/29abc50f07a4ebe68cb4f31981884f89b2157d7e4ed63b09631d40c0717faa94?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/29abc50f07a4ebe68cb4f31981884f89b2157d7e4ed63b09631d40c0717faa94?s=96&d=mm&r=g","caption":"Luke Smith"},"description":"I\u2019ve been working with Microsoft Technologies for over 20 years, my main focus now being Microsoft Online Services. I manage the Cloud Services at ElysianIT Limited and as a P-SELLER at Microsoft. I have worked with many organisations from SMC to Enterprise. I\u2019ve been working with Microsoft Technologies since DOS 5.0, to date I have been working on Microsoft\u2019s latest cloud technology Windows Azure, Windows 10 Office 365 and Microsoft SharePoint","sameAs":["http:\/\/www.tsls.co.uk"],"url":"https:\/\/www.tsls.co.uk\/index.php\/author\/luke\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2gf1k-1m","_links":{"self":[{"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/84","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":1,"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"predecessor-version":[{"id":6441,"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/84\/revisions\/6441"}],"wp:attachment":[{"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}