 




<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: cursors left open in embedded SQL</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/cursors-left-open-in-embedded-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/cursors-left-open-in-embedded-sql/</link>
	<description></description>
	<lastBuildDate>Fri, 24 May 2013 12:17:28 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: tomliotta</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/cursors-left-open-in-embedded-sql/#comment-83790</link>
		<dc:creator>tomliotta</dc:creator>
		<pubDate>Sun, 14 Nov 2010 11:07:31 +0000</pubDate>
		<guid isPermaLink="false">#comment-83790</guid>
		<description><![CDATA[There&#039;s no need for a cursor for a count even with a variable WHERE clause:&lt;pre&gt;
     Hdatedit(*ymd) nomain
     DgetVI            pr             5i 0
     D viKey                         10    const

     PgetVI            b                   export
     DgetVI            pi             5i 0
     D viKey                         10    const

     D viCount         s              5i 0

     C/exec sql values ( select count(*) from accpth
     c+                  where apfile = :viKey ) into :viCount
     C/end-exec

     C                   return    viCount
     P                 e&lt;/pre&gt;
That returns a COUNT() for any variable viKey passed into that WHERE clause. But perhaps you mean something different. An example that shows what you need might be useful.

Tom]]></description>
		<content:encoded><![CDATA[<p>There&#8217;s no need for a cursor for a count even with a variable WHERE clause:
<pre>
     Hdatedit(*ymd) nomain
     DgetVI            pr             5i 0
     D viKey                         10    const

     PgetVI            b                   export
     DgetVI            pi             5i 0
     D viKey                         10    const

     D viCount         s              5i 0

     C/exec sql values ( select count(*) from accpth
     c+                  where apfile = :viKey ) into :viCount
     C/end-exec

     C                   return    viCount
     P                 e</pre>
<p>That returns a COUNT() for any variable viKey passed into that WHERE clause. But perhaps you mean something different. An example that shows what you need might be useful.</p>
<p>Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chance</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/cursors-left-open-in-embedded-sql/#comment-47261</link>
		<dc:creator>chance</dc:creator>
		<pubDate>Thu, 23 Feb 2006 14:25:30 +0000</pubDate>
		<guid isPermaLink="false">#comment-47261</guid>
		<description><![CDATA[Thanks for your response Vatchy.  The portion of your response &quot;Execute w@Statement&quot; pointed me to the right topic in a manual that we have. 

Unfortunately, the &quot;prepare&quot;/&quot;execute&quot; method will not work with a Select statement.  I thought I&#039;d give it a try anyway, and got SQLSTT of 42618 (host variable not permitted here).  It looks like the cursor is the way I will have to go to get the record count fetched into a host variable (since I have a dynamic &quot;where&quot; clause).  
]]></description>
		<content:encoded><![CDATA[<p>Thanks for your response Vatchy.  The portion of your response &#8220;Execute w@Statement&#8221; pointed me to the right topic in a manual that we have. </p>
<p>Unfortunately, the &#8220;prepare&#8221;/&#8221;execute&#8221; method will not work with a Select statement.  I thought I&#8217;d give it a try anyway, and got SQLSTT of 42618 (host variable not permitted here).  It looks like the cursor is the way I will have to go to get the record count fetched into a host variable (since I have a dynamic &#8220;where&#8221; clause).  </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vatchy</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/cursors-left-open-in-embedded-sql/#comment-47262</link>
		<dc:creator>vatchy</dc:creator>
		<pubDate>Thu, 23 Feb 2006 07:54:12 +0000</pubDate>
		<guid isPermaLink="false">#comment-47262</guid>
		<description><![CDATA[Use the prepare statement.  Here is an example that I keep lying around:

/Free
   w@Cmd = &#039;Create Alias QTEMP/ALIAS1 For &#039;
        + %Trim(s1OrigLib) + &#039;/&#039; + %Trim(s1OrigFile)
        + &#039;(&#039; + %Trim(s1Member) + &#039;)&#039;;
/End-Free

C/Exec SQL                           
C+    Prepare w@Statement From :w@Cmd
C/End-Exec                           

C/Exec SQL               
C+    Execute w@Statement
C/End-Exec               

Obviously the SQL statement in w@Cmd isn&#039;t relevant to what you are doing but you should get the idea on how to do it for your problem.]]></description>
		<content:encoded><![CDATA[<p>Use the prepare statement.  Here is an example that I keep lying around:</p>
<p>/Free<br />
   w@Cmd = &#8216;Create Alias QTEMP/ALIAS1 For &#8216;<br />
        + %Trim(s1OrigLib) + &#8216;/&#8217; + %Trim(s1OrigFile)<br />
        + &#8216;(&#8216; + %Trim(s1Member) + &#8216;)&#8217;;<br />
/End-Free</p>
<p>C/Exec SQL<br />
C+    Prepare w@Statement From :w@Cmd<br />
C/End-Exec                           </p>
<p>C/Exec SQL<br />
C+    Execute w@Statement<br />
C/End-Exec               </p>
<p>Obviously the SQL statement in w@Cmd isn&#8217;t relevant to what you are doing but you should get the idea on how to do it for your problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chance</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/cursors-left-open-in-embedded-sql/#comment-47263</link>
		<dc:creator>chance</dc:creator>
		<pubDate>Wed, 22 Feb 2006 10:11:15 +0000</pubDate>
		<guid isPermaLink="false">#comment-47263</guid>
		<description><![CDATA[First of all, thank you DaddyCOZ.  The change in the compile option worked.  Your help is greatly appreciated.

Now I have a question for Vatchy concerning not having to declare a cursor to obtain a record count.  My situation is that the &quot;where&quot; part of the select statement will be dynamic.  The only examples I have found which involved a dynamic select stmt always used a cursor.  In view of the dynamic nature of the select, is there a way to obtain the count without a cursor?
]]></description>
		<content:encoded><![CDATA[<p>First of all, thank you DaddyCOZ.  The change in the compile option worked.  Your help is greatly appreciated.</p>
<p>Now I have a question for Vatchy concerning not having to declare a cursor to obtain a record count.  My situation is that the &#8220;where&#8221; part of the select statement will be dynamic.  The only examples I have found which involved a dynamic select stmt always used a cursor.  In view of the dynamic nature of the select, is there a way to obtain the count without a cursor?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vatchy</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/cursors-left-open-in-embedded-sql/#comment-47264</link>
		<dc:creator>vatchy</dc:creator>
		<pubDate>Wed, 22 Feb 2006 07:50:55 +0000</pubDate>
		<guid isPermaLink="false">#comment-47264</guid>
		<description><![CDATA[In addition, you don&#039;t need a cursor in order to get a record count.  Just run the SQL Select statement without declaring it in a cursor.]]></description>
		<content:encoded><![CDATA[<p>In addition, you don&#8217;t need a cursor in order to get a record count.  Just run the SQL Select statement without declaring it in a cursor.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/10 queries in 0.036 seconds using memcached
Object Caching 323/329 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-24 12:18:12 -->