<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www2.sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Running sums yet again: SQLCLR saves the day!</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/running-sums-yet-again-sqlclr-saves-the-day.aspx</link><description>Back again! Fourth post for the month of February, making this my best posting month in, well, months. Expect this trend to continue. After yesterday's post on running sums and the evils of cursors , Jamie Thompson came up with a faster solution than</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: Running sums yet again: SQLCLR saves the day!</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/running-sums-yet-again-sqlclr-saves-the-day.aspx#112</link><pubDate>Thu, 13 Jul 2006 16:54:05 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:112</guid><dc:creator>Jeff Smith</dc:creator><description>Hi Adam -- great post. &amp;nbsp;It reminds me a lot of my post about doing cross tabs at the client instead of trying to jump through hoops to do them in T-SQL. &amp;nbsp;And the results are the same -- not only is it easier to do these things at the client, it is faster! &amp;nbsp;&lt;br&gt;&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://weblogs.sqlteam.com/jeffs/archive/2005/05/12/5127.aspx"&gt;http://weblogs.sqlteam.com/jeffs/archive/2005/05/12/5127.aspx&lt;/a&gt;&lt;br&gt;&lt;br&gt;The only time that SQL Server should be calculating running sums is when those values are needed for further processing within SQL Server (i.e., to store in a table or to calc percentages or something like that). &amp;nbsp;As I often say, if people will just use SQL the way it is intended they would be surprised at how much simplier their code is and how much easier their lives are!&lt;br&gt;&lt;br&gt;Great blog, the site looks great, looking forward to your posts. &amp;nbsp;</description></item><item><title>re: Running sums yet again: SQLCLR saves the day!</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/running-sums-yet-again-sqlclr-saves-the-day.aspx#1231</link><pubDate>Tue, 08 May 2007 22:28:48 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:1231</guid><dc:creator>stook</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;great post.&lt;/p&gt;
&lt;p&gt;the update syntax is not undocumented actually. At least my sql 2000 help says:&lt;/p&gt;
&lt;p&gt;SET @variable = column = expression sets the variable to the same value as the column. This differs from SET @variable = column, column = expression, which sets the variable to the pre-update value of the column.&lt;/p&gt;
&lt;p&gt;SQLCLR is faster of course, but the SET is simpler one.&lt;/p&gt;
&lt;p&gt;About performance tests - if these take less then 10 seconds I'll usualy make a 100 loop for timing to be sure.&lt;/p&gt;
</description></item><item><title>re: Running sums yet again: SQLCLR saves the day!</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/running-sums-yet-again-sqlclr-saves-the-day.aspx#1277</link><pubDate>Tue, 22 May 2007 18:13:12 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:1277</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Hi Stook,&lt;/p&gt;
&lt;p&gt;That's technically only documented for a single row; the result of a multirow operation is what is not documented (and not deterministic).&lt;/p&gt;
</description></item><item><title>"Cursors Run Just Fine"</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/running-sums-yet-again-sqlclr-saves-the-day.aspx#2952</link><pubDate>Sat, 13 Oct 2007 14:06:39 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2952</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;I found Linchi's recent post on use of cursors in the TPC-E test to be quite interesting. The question&lt;/p&gt;
</description></item><item><title>re: Running sums yet again: SQLCLR saves the day!</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/running-sums-yet-again-sqlclr-saves-the-day.aspx#3503</link><pubDate>Sun, 25 Nov 2007 01:41:15 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:3503</guid><dc:creator>Kevin Boles</dc:creator><description>&lt;p&gt;Per Hugo's blog here, &lt;a rel="nofollow" target="_new" href="http://sqlblog.com/blogs/hugo_kornelis/archive/2007/11/21/curious-cursor-optimization-options.aspx"&gt;http://sqlblog.com/blogs/hugo_kornelis/archive/2007/11/21/curious-cursor-optimization-options.aspx&lt;/a&gt;, you can actually get the TSQL cursor solution to run a tad faster. &amp;nbsp;Instead of this for the cursor declaration:&lt;/p&gt;
&lt;p&gt;CURSOR LOCAL FAST_FORWARD &amp;nbsp;FOR&lt;/p&gt;
&lt;p&gt;try this:&lt;/p&gt;
&lt;p&gt;CURSOR LOCAL FORWARD_ONLY STATIC &amp;nbsp;FOR&lt;/p&gt;
&lt;p&gt;On my mondo test server . . . er laptop :), I was able to cut runtime from 5.56 seconds to 4.82 seconds average time. &amp;nbsp;13.3% faster if I did the math correctly.&lt;/p&gt;
&lt;p&gt;Really blows my mind to find that FAST_FORWARD isn't the fastest cursor! &amp;nbsp;I have been advising clients and students for years to use that 'optimization' if they absolutely had to use a cursor. &amp;nbsp;oopsie!&lt;/p&gt;
</description></item><item><title>re: Running sums yet again: SQLCLR saves the day!</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/running-sums-yet-again-sqlclr-saves-the-day.aspx#10218</link><pubDate>Mon, 01 Dec 2008 15:17:10 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:10218</guid><dc:creator>David</dc:creator><description>&lt;p&gt;Did some tests with:&lt;/p&gt;
&lt;p&gt;LOCAL FAST_FORWARD&lt;/p&gt;
&lt;p&gt;vs&lt;/p&gt;
&lt;p&gt;LOCAL READ_ONLY FORWARD_ONLY STATIC&lt;/p&gt;
&lt;p&gt;(note the READ_ONLY might speed things up a bit)&lt;/p&gt;
&lt;p&gt;And it seemed the FORWARD_ONLY approach was faster only on SQL 2000 and not 2005.&lt;/p&gt;
</description></item></channel></rss>