<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://completit.com/communityserver/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>Ivan Dragoev's Blog</title><link>http://completit.com/communityserver/blogs/idragoev/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.2)</generator><item><title>IsNumeric and Cast headache</title><link>http://completit.com/communityserver/blogs/idragoev/archive/2009/02/13/isnumeric-and-cast-headache.aspx</link><pubDate>Fri, 13 Feb 2009 15:04:00 GMT</pubDate><guid isPermaLink="false">456c5cc1-fe21-4ac2-8669-11477cec168e:16254</guid><dc:creator>idragoev</dc:creator><slash:comments>0</slash:comments><comments>http://completit.com/communityserver/blogs/idragoev/comments/16254.aspx</comments><wfw:commentRss>http://completit.com/communityserver/blogs/idragoev/commentrss.aspx?PostID=16254</wfw:commentRss><description>&lt;p&gt;An interesting issue was found by a colleague of mine: an exception when cast a nvarchar column to integer even if the column value was checked with IsNumeric on SQL 2000 SP4:&lt;/p&gt;&lt;div&gt;&lt;pre style="PADDING-RIGHT:0px;PADDING-LEFT:0px;FONT-SIZE:8pt;PADDING-BOTTOM:0px;MARGIN:0em;OVERFLOW:visible;WIDTH:100%;COLOR:black;BORDER-TOP-STYLE:none;LINE-HEIGHT:12pt;PADDING-TOP:0px;FONT-FAMILY:consolas, 'Courier New', courier, monospace;BORDER-RIGHT-STYLE:none;BORDER-LEFT-STYLE:none;BACKGROUND-COLOR:#f4f4f4;BORDER-BOTTOM-STYLE:none;"&gt;&lt;span style="COLOR:#0000ff;"&gt;select&lt;/span&gt; c.ID&lt;span style="COLOR:#0000ff;"&gt;from&lt;/span&gt; dbo.COM_COMPANY c &lt;span style="COLOR:#0000ff;"&gt;where&lt;/span&gt; IsNumeric(c.CODE) = 1 &lt;span style="COLOR:#0000ff;"&gt;and&lt;/span&gt; &lt;span style="COLOR:#0000ff;"&gt;convert&lt;/span&gt;(c.CODE &lt;span style="COLOR:#0000ff;"&gt;as&lt;/span&gt; &lt;span style="COLOR:#0000ff;"&gt;int&lt;/span&gt;) = 304 and DELETED = 0&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As result the following exception were raised:&lt;/p&gt;&lt;div&gt;&lt;pre style="PADDING-RIGHT:0px;PADDING-LEFT:0px;FONT-SIZE:8pt;PADDING-BOTTOM:0px;MARGIN:0em;OVERFLOW:visible;WIDTH:100%;COLOR:black;BORDER-TOP-STYLE:none;LINE-HEIGHT:12pt;PADDING-TOP:0px;FONT-FAMILY:consolas, 'Courier New', courier, monospace;BORDER-RIGHT-STYLE:none;BORDER-LEFT-STYLE:none;BACKGROUND-COLOR:#f4f4f4;BORDER-BOTTOM-STYLE:none;"&gt;Msg 245, &lt;span style="COLOR:#0000ff;"&gt;Level&lt;/span&gt; 16, &lt;span style="COLOR:#0000ff;"&gt;State&lt;/span&gt; 1, Line 1Syntax error converting the nvarchar &lt;span style="COLOR:#0000ff;"&gt;value&lt;/span&gt; &lt;span style="COLOR:#006080;"&gt;'9665a'&lt;/span&gt; &lt;span style="COLOR:#0000ff;"&gt;to&lt;/span&gt; a &lt;span style="COLOR:#0000ff;"&gt;column&lt;/span&gt; &lt;span style="COLOR:#0000ff;"&gt;of&lt;/span&gt; &lt;span style="COLOR:#0000ff;"&gt;data&lt;/span&gt; type &lt;span style="COLOR:#0000ff;"&gt;int&lt;/span&gt;.&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I played a bit with this query and I found the following: if I delete the check for the DELETED flag it works fine. But when I add one more check then it throws an exception. Here the working version:&lt;/p&gt;&lt;div&gt;&lt;pre style="PADDING-RIGHT:0px;PADDING-LEFT:0px;FONT-SIZE:8pt;PADDING-BOTTOM:0px;MARGIN:0em;OVERFLOW:visible;WIDTH:100%;COLOR:black;BORDER-TOP-STYLE:none;LINE-HEIGHT:12pt;PADDING-TOP:0px;FONT-FAMILY:consolas, 'Courier New', courier, monospace;BORDER-RIGHT-STYLE:none;BORDER-LEFT-STYLE:none;BACKGROUND-COLOR:#f4f4f4;BORDER-BOTTOM-STYLE:none;"&gt;&lt;span style="COLOR:#0000ff;"&gt;select&lt;/span&gt; c.ID&lt;span style="COLOR:#0000ff;"&gt;from&lt;/span&gt; dbo.COM_COMPANY c &lt;span style="COLOR:#0000ff;"&gt;where&lt;/span&gt; IsNumeric(c.CODE) = 1 &lt;span style="COLOR:#0000ff;"&gt;and&lt;/span&gt; &lt;span style="COLOR:#0000ff;"&gt;convert&lt;/span&gt;(c.CODE &lt;span style="COLOR:#0000ff;"&gt;as&lt;/span&gt; &lt;span style="COLOR:#0000ff;"&gt;int&lt;/span&gt;) = 304&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But I really need to have more checks, so what can I do?&lt;/p&gt;&lt;p&gt;The answer is:&lt;/p&gt;&lt;div&gt;&lt;pre style="PADDING-RIGHT:0px;PADDING-LEFT:0px;FONT-SIZE:8pt;PADDING-BOTTOM:0px;MARGIN:0em;OVERFLOW:visible;WIDTH:100%;COLOR:black;BORDER-TOP-STYLE:none;LINE-HEIGHT:12pt;PADDING-TOP:0px;FONT-FAMILY:consolas, 'Courier New', courier, monospace;BORDER-RIGHT-STYLE:none;BORDER-LEFT-STYLE:none;BACKGROUND-COLOR:#f4f4f4;BORDER-BOTTOM-STYLE:none;"&gt;&lt;span style="COLOR:#0000ff;"&gt;select&lt;/span&gt; c.ID&lt;span style="COLOR:#0000ff;"&gt;from&lt;/span&gt; dbo.COM_COMPANY c &lt;span style="COLOR:#0000ff;"&gt;where&lt;/span&gt; DELETED = 0 &lt;span style="COLOR:#0000ff;"&gt;and&lt;/span&gt;     (&lt;span style="COLOR:#0000ff;"&gt;case&lt;/span&gt; &lt;span style="COLOR:#0000ff;"&gt;when&lt;/span&gt; IsNumeric(c.CODE) = 1 &lt;span style="COLOR:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="COLOR:#0000ff;"&gt;cast&lt;/span&gt;(c.CODE &lt;span style="COLOR:#0000ff;"&gt;as&lt;/span&gt; &lt;span style="COLOR:#0000ff;"&gt;int&lt;/span&gt;) &lt;span style="COLOR:#0000ff;"&gt;else&lt;/span&gt; -1 &lt;span style="COLOR:#0000ff;"&gt;end&lt;/span&gt;) = 304&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This one works just fine.&lt;/p&gt;&lt;p&gt;Enjoy the workaround ;-)&lt;/p&gt;&lt;img src="http://completit.com/communityserver/aggbug.aspx?PostID=16254" width="1" height="1"&gt;</description><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/exception/default.aspx">exception</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/cast/default.aspx">cast</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/SQL+2005/default.aspx">SQL 2005</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/IsNumeric/default.aspx">IsNumeric</category></item><item><title>Missing exceptions in code after Raiserror() and SET NOCOUNT ON workaround</title><link>http://completit.com/communityserver/blogs/idragoev/archive/2008/12/19/missing-exceptions-in-code-after-raiserror-and-set-nocount-on-workaround.aspx</link><pubDate>Fri, 19 Dec 2008 10:59:52 GMT</pubDate><guid isPermaLink="false">456c5cc1-fe21-4ac2-8669-11477cec168e:11905</guid><dc:creator>idragoev</dc:creator><slash:comments>0</slash:comments><comments>http://completit.com/communityserver/blogs/idragoev/comments/11905.aspx</comments><wfw:commentRss>http://completit.com/communityserver/blogs/idragoev/commentrss.aspx?PostID=11905</wfw:commentRss><description>&lt;p class="MsoNormal"&gt;&lt;span style="mso-ansi-language:en-us;"&gt;These days I worked on a problem related with using raiserror() in SQL 2000 and why the exception is not raised in ADO.NET application using ODBCCommand. What I had is a simple stored procedure, that performs some check on its parameters and if some of them are incorrect it raises error and exits: &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:;"&gt;create&lt;/span&gt;&lt;span style="font-size:10pt;font-family:;"&gt; &lt;span style="color:blue;"&gt;procedure&lt;/span&gt; dbo&lt;span style="color:gray;"&gt;.&lt;/span&gt;TestRaiserrrorinCode &lt;span style="color:gray;"&gt;(&lt;/span&gt;@ClientCode &lt;span style="color:blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;10&lt;span style="color:gray;"&gt;))&lt;/span&gt; &lt;span style="color:blue;"&gt;as &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:;"&gt;&lt;/span&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:;"&gt;if&lt;/span&gt;&lt;span style="font-size:10pt;font-family:;"&gt; &lt;span style="color:gray;"&gt;not&lt;/span&gt; &lt;span style="color:gray;"&gt;exists&lt;/span&gt; &lt;span style="color:gray;"&gt;( &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:;"&gt;&lt;span style="mso-tab-count:1;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;select&lt;/span&gt; Id &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:;"&gt;&lt;span style="mso-tab-count:1;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;from&lt;/span&gt; dbo&lt;span style="color:gray;"&gt;.&lt;/span&gt;Clients &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:;"&gt;&lt;span style="mso-tab-count:1;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;where&lt;/span&gt; Code &lt;span style="color:gray;"&gt;=&lt;/span&gt; @ClientCode&lt;span style="color:gray;"&gt;) &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:;"&gt;begin &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:;"&gt;&lt;span style="mso-tab-count:1;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;raiserror&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;58005&lt;span style="color:gray;"&gt;,&lt;/span&gt; 16&lt;span style="color:gray;"&gt;,&lt;/span&gt; 1&lt;span style="color:gray;"&gt;,&lt;/span&gt; @ClientCode&lt;span style="color:gray;"&gt;) &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:;"&gt;&lt;span style="mso-tab-count:1;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; 58005 &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;color:blue;line-height:115%;font-family:;"&gt;end&lt;/span&gt;&lt;span style="font-size:10pt;color:blue;line-height:115%;font-family:;"&gt; &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:;"&gt;&lt;/span&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;color:blue;line-height:115%;font-family:;"&gt;print&lt;/span&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:;"&gt; &lt;span style="color:red;"&gt;'Do Something'&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:10pt;color:red;line-height:115%;font-family:;"&gt; &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;color:blue;line-height:115%;font-family:;"&gt;&lt;/span&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="mso-ansi-language:en-us;"&gt;If you execute it in SSMS you will see: &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:8pt;font-family:;"&gt;&lt;font color="#ff0000"&gt;Msg 58005, Level 16, State 1, Procedure TestRaiserrrorinCode, Line 8 &lt;/font&gt;&lt;/span&gt;    &lt;p&gt;&lt;font color="#ff0000"&gt;&lt;/font&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;font color="#ff0000"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;font color="#ff0000"&gt;&lt;span style="font-size:8pt;line-height:115%;font-family:;"&gt;Cannot find &lt;/span&gt;&lt;span style="font-size:8pt;line-height:115%;font-family:;"&gt;client&lt;/span&gt;&lt;span style="font-size:8pt;line-height:115%;font-family:;"&gt; with &lt;/span&gt;&lt;span style="font-size:8pt;line-height:115%;font-family:;"&gt;c&lt;/span&gt;&lt;span style="font-size:8pt;line-height:115%;font-family:;"&gt;ode '34'.&lt;/span&gt;&lt;/font&gt;&lt;span style="mso-ansi-language:en-us;"&gt; &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="mso-ansi-language:en-us;"&gt;As you can see, because of the return the print does nothing. So in the SQL it works fine. &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="mso-ansi-language:en-us;"&gt;But what if you execute this procedure from the C# code using ExecuteNonQuery()? The exception is not raised and the procedure seems to be executed normally. But it is not &amp;#8211; there is no exception in the C# code, but the procedure didn&amp;#8217;t execute successfully either. &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="mso-ansi-language:en-us;"&gt;I started my investigation by playing sit SET XACT_ABORT ON, but it didn&amp;#8217;t help &amp;#8211; it was not related to this situation. &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="mso-ansi-language:en-us;"&gt;I tried to remove the return after the raiserror() call, but as you might know raiserror() do not stop the execution so I get &amp;#8216;Do something&amp;#8217; printed, which is not acceptable. &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="mso-ansi-language:en-us;"&gt;What&amp;#8217;s the solution? &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="mso-ansi-language:en-us;"&gt;I&amp;#8217;ve noticed that I have missed the &lt;strong&gt;SET NOCOUNT ON&lt;/strong&gt; and decided to add it. And miraculously it helped. The procedure worked fine, the C# code throws the exception. &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="mso-ansi-language:en-us;"&gt;How and why the &lt;strong&gt;SET NOCOUNT &lt;/strong&gt;to&lt;strong&gt; ON&lt;/strong&gt; affects this &amp;#8211; I do not know. But the fact is that without it the procedure does not behave as it is expected. &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="mso-ansi-language:en-us;"&gt;Hope that helps you! &lt;/span&gt;&lt;/p&gt;&lt;img src="http://completit.com/communityserver/aggbug.aspx?PostID=11905" width="1" height="1"&gt;</description></item><item><title>Animating ListBox items - the VisualStateManager</title><link>http://completit.com/communityserver/blogs/idragoev/archive/2008/06/13/animating-listbox-items-the-visualstatemanager.aspx</link><pubDate>Fri, 13 Jun 2008 13:13:00 GMT</pubDate><guid isPermaLink="false">456c5cc1-fe21-4ac2-8669-11477cec168e:4337</guid><dc:creator>idragoev</dc:creator><slash:comments>0</slash:comments><comments>http://completit.com/communityserver/blogs/idragoev/comments/4337.aspx</comments><wfw:commentRss>http://completit.com/communityserver/blogs/idragoev/commentrss.aspx?PostID=4337</wfw:commentRss><description>&lt;P&gt;Check out my &lt;A class="" href="http://www.silverlightshow.net/items/Animating-ListBox-items-the-VisualStateManager.aspx"&gt;second article on ListBox items animations&lt;/A&gt;. Here you can see how to use VisualStateManager and also some problems I faced during the migration to Silverlight 2 beta 2&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://completit.com/communityserver/aggbug.aspx?PostID=4337" width="1" height="1"&gt;</description><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Interactive Silverlight Voting Control</title><link>http://completit.com/communityserver/blogs/idragoev/archive/2007/12/05/interactive-silverlight-voting-control.aspx</link><pubDate>Wed, 05 Dec 2007 14:43:00 GMT</pubDate><guid isPermaLink="false">456c5cc1-fe21-4ac2-8669-11477cec168e:1157</guid><dc:creator>idragoev</dc:creator><slash:comments>0</slash:comments><comments>http://completit.com/communityserver/blogs/idragoev/comments/1157.aspx</comments><wfw:commentRss>http://completit.com/communityserver/blogs/idragoev/commentrss.aspx?PostID=1157</wfw:commentRss><description>&lt;P&gt;As you might know, we at CompletIT are behind the&amp;nbsp;&lt;A href="http://www.silverlightshow.net/Default.aspx"&gt;SilverlightShow.net&lt;/A&gt; - the independent Silverlight community site. Also, the last few weeks we've published several articles (with source code included) just to show how easy is to create nice&amp;nbsp;stuff with&amp;nbsp;Silverlight 1.1.&lt;/P&gt;
&lt;P&gt;I also decided to write an article based on simple &lt;A class="" href="http://www.silverlightshow.net/items/2477.aspx"&gt;interactive voting control&lt;/A&gt;. The purpose of this control is to show the current results for certain vote. The site visitors can give their vote simply by clicking on the option result they like and the results are automatically updated.&lt;/P&gt;
&lt;P&gt;We will continue publishing articles with source code. We hope such examples are helpful for&amp;nbsp;the developers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;You can submit your own&amp;nbsp;article Silverlight on &lt;A href="http://www.silverlightshow.net/Default.aspx"&gt;SilverlightShow.net&lt;/A&gt;&amp;nbsp;- just click &lt;A class="" href="http://www.silverlightshow.net/SubmitArticle.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://completit.com/communityserver/aggbug.aspx?PostID=1157" width="1" height="1"&gt;</description><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/SilverlightShow/default.aspx">SilverlightShow</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/Silverlight+Control/default.aspx">Silverlight Control</category></item><item><title>CompletIT at DevReach, Sofia, Bulgaria 1-2 October, 2007</title><link>http://completit.com/communityserver/blogs/idragoev/archive/2007/10/08/ms-sql-triggers-inserted-deleted-tables.aspx</link><pubDate>Mon, 08 Oct 2007 15:36:00 GMT</pubDate><guid isPermaLink="false">456c5cc1-fe21-4ac2-8669-11477cec168e:208</guid><dc:creator>idragoev</dc:creator><slash:comments>0</slash:comments><comments>http://completit.com/communityserver/blogs/idragoev/comments/208.aspx</comments><wfw:commentRss>http://completit.com/communityserver/blogs/idragoev/commentrss.aspx?PostID=208</wfw:commentRss><description>&lt;P&gt;At the beginning of October I have visited DevReach - the premier conference for Microsoft technologies in South Eastern Europe. I was on several lectures about MS SQL:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;What's New in SQL Server 2008 for Developers - by Vladi Tchalkov;&lt;/LI&gt;
&lt;LI&gt;T–SQL Querying: Tips and Techniques (With SQL 2008 features too) by Stephen Forte;&lt;/LI&gt;
&lt;LI&gt;Lino Does LINQ by Lino Tadros;&lt;/LI&gt;
&lt;LI&gt;Being Smart About Database Design by Vladi Tchalkov,&lt;/LI&gt;
&lt;LI&gt;100 Years of Transaction Solitude...Transactions and isolation levels by Ami Levin;&lt;/LI&gt;
&lt;LI&gt;SQL Server Service Broker - Your Gateway to the World of Transactional Asynchronicity by Ami Levin;&lt;/LI&gt;
&lt;LI&gt;Security and .NET by Hadi Hariri;&lt;/LI&gt;
&lt;LI&gt;Silverlight, Flash on Steroids by Lino Tadros.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;What I appreciated most is the fact, that I had the chance to discuss different topics with the speakers. Most of them are experienced, well known in the community, with knowledge about the cutting-edge MS technologies.&lt;/P&gt;
&lt;P&gt;I’m looking forward to meeting the guys again.&lt;BR&gt;&lt;/P&gt;&lt;img src="http://completit.com/communityserver/aggbug.aspx?PostID=208" width="1" height="1"&gt;</description><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/DevReach/default.aspx">DevReach</category></item><item><title>How to select the primary key data type?</title><link>http://completit.com/communityserver/blogs/idragoev/archive/2007/07/04/how-to-select-the-primary-key-data-type.aspx</link><pubDate>Thu, 05 Jul 2007 08:00:00 GMT</pubDate><guid isPermaLink="false">456c5cc1-fe21-4ac2-8669-11477cec168e:34</guid><dc:creator>idragoev</dc:creator><slash:comments>0</slash:comments><comments>http://completit.com/communityserver/blogs/idragoev/comments/34.aspx</comments><wfw:commentRss>http://completit.com/communityserver/blogs/idragoev/commentrss.aspx?PostID=34</wfw:commentRss><description>&lt;P&gt;When a new database is about to be designed, have to think about&amp;nbsp;what data type to use for the primary keys. There are several things that should be taken into consideration: the average database size expected, the possibility of growing in the future, replication or other data synchronization needs, etc. Here I will try to give you a simple way for primary key type selection depending on the database you have to design.&lt;/P&gt;
&lt;P&gt;When I design database I'm trying to follow several simple rules:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Add column named ID in each table and set it as primary key; 
&lt;LI&gt;Do not use logical primary keys as physical primary keys: Client table&amp;nbsp;have column ID as PK and Code as logical PK, but ID column will be used in relations; 
&lt;LI&gt;Use stored procedure for data fetching and manipulation - makes database changes easier, no recompilation of existing applications needed; 
&lt;LI&gt;Avoid auto increment columns - you never know what the value for the PK will be until the row is stored in the database - means no control;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Generally I always have to choose between 16-byte uniqueidentifier and 4-byte int. The INTs are smaller, easy to remember, meaningfully to the user and easy to make them sequent. The uniqueidentifiers are simply unique and have unlimited values.&lt;/P&gt;
&lt;P&gt;The primary keys of type int are smaller, which means smaller indexes and better performance. It is also easy to keep the values in a sequence - either by using auto increment (not recommended) or any other way to get the next value. This allows to make clustered index on the column too without performance impact.&lt;/P&gt;
&lt;P&gt;The disadvantage of INTs are that you need some logic for obtaining new value. If auto increment is used, then inserting master-detail data might be more complicated, because the primary key value is unknown until the record is stored. This problem can be solved by using stored procedures and logical keys to link master-details.&lt;/P&gt;
&lt;P&gt;To add new record when the primary key is unique identifier is easy. But here the size is 4 times bigger! Also you should never make clustered index on it because inserting new records are not sequential and causes the index to be reorganized each time.&lt;/P&gt;
&lt;P&gt;The unique identifiers are only useful when you need to synchronize data between databases or you have application that might work off line. If INTs are used, you can have problems with doubled IDs because another user might use the same values for&amp;nbsp;the new records - in this case you need to implement a logic to renumber the PK and all related records and to update the clients with the new values.&lt;/P&gt;
&lt;P&gt;What I think is best is to combine the advantages of the INTS with the uniqueness of the guids. Make the primary key of type int, and add additional column of type uniqueidentifier only if you need data synchronization. This is the way the replication works - using rowguid column.&lt;/P&gt;&lt;img src="http://completit.com/communityserver/aggbug.aspx?PostID=34" width="1" height="1"&gt;</description><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/PK/default.aspx">PK</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/database+design/default.aspx">database design</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/Primary+Key/default.aspx">Primary Key</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/uniqueidentifier/default.aspx">uniqueidentifier</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/GUID/default.aspx">GUID</category></item><item><title>Increase Stored Procedure execution performance dramatically</title><link>http://completit.com/communityserver/blogs/idragoev/archive/2007/06/18/increase-stored-procedure-execution-performance.aspx</link><pubDate>Mon, 18 Jun 2007 14:52:00 GMT</pubDate><guid isPermaLink="false">456c5cc1-fe21-4ac2-8669-11477cec168e:24</guid><dc:creator>idragoev</dc:creator><slash:comments>0</slash:comments><comments>http://completit.com/communityserver/blogs/idragoev/comments/24.aspx</comments><wfw:commentRss>http://completit.com/communityserver/blogs/idragoev/commentrss.aspx?PostID=24</wfw:commentRss><description>&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;Last month we spent a lot of time in data loading optimization due to performance problems. I started with optimization of the heaviest views and put them in parameterized &lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/span&gt;stored procedures . I also used a simple method to check the performance by measuring the time needed for execution. I was using MS SQL Management studio. During the test I had the following source with some local variables declared:&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;declare&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Param1 int,&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @param2 int,&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @TraceStart datetime&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Set @TraceStart = GetDate()&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Select Column1, Column2, ….&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;From Table1&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Join …&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Where Column1 = @Param1 and …&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;…&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Select DateDiff(ms, @TraceStart, GetDate())&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;The idea was simple – to test, and then to place the same code in a stored procedure, and the declared local variables to be introduced as parameters. I managed to optimize the view drastically – from 500ms down to 1. And I was pretty happy.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;Then I made the stored procedure:&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Create procedure LoadData(@Param1 int @param2 int)&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Select Column1, Column2, ….&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;From Table1&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Join …&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Where Column1 = @Param1 and …&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;Then I executed it using the following approach:&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;declare&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Param1 int,&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @param2 int,&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @TraceStart datetime&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Set @TraceStart = GetDate()&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Exec LoadData @Param1 int @param2 int&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Select DateDiff(ms, @TraceStart, GetDate())&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;The results bring me a hard attack: more than 10 minutes!!!&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri" size="3"&gt;Thanks to a friend of mine – &lt;/font&gt;&lt;a href="http://dreams.a-wake.net/"&gt;&lt;font face="Calibri" color="#800080" size="3"&gt;Petar Atanasov&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt; – we solved the problem. He&amp;nbsp;advised me to make a local copy of the parameters and to use them in the procedure’s body and that's&amp;nbsp;exactly what I did:&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Create procedure LoadData(@Param1_ int @param2_ int)&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;declare&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Param1 int,&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @param2 int,&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Set @Param1 = @Param1_&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Set @param2 = @Param2_&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Select Column1, Column2, ….&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;From Table1&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Join …&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;span style="font-size:10pt;color:#3366ff;"&gt;Where Column1 = @Param1 and …&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri" size="3"&gt;And that was it! The stored procedure was executed for less than 1ms!!!&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;/o:p&gt;&lt;font face="Calibri"&gt;&amp;nbsp;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;font face="Calibri" size="3"&gt;The problem is that the query optimizer cannot make a good execution plan if the parameters are directly used, but it can if local variables are used – especially for date time parameters.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://completit.com/communityserver/aggbug.aspx?PostID=24" width="1" height="1"&gt;</description><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/execution+plan/default.aspx">execution plan</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/optimization/default.aspx">optimization</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/Stored+Procedure/default.aspx">Stored Procedure</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/Performance/default.aspx">Performance</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/Stored+Procedure+execution/default.aspx">Stored Procedure execution</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/sql+optimization/default.aspx">sql optimization</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/sql+stored+procedure+optimization/default.aspx">sql stored procedure optimization</category><category domain="http://completit.com/communityserver/blogs/idragoev/archive/tags/database+design/default.aspx">database design</category></item></channel></rss>