<?xml version="1.0" encoding="iso-8859-1"?><!-- generator="b2evolution/4.0.3" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Data Management - Author(s): Kevin Conan</title>
		<link>http://blogs.lessthandot.com/index.php/DataMgmt/</link>
		<atom:link rel="self" type="application/rss+xml" href="http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2" />
		<description></description>
		<language>en-GB</language>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=4.0.3"/>
		<ttl>60</ttl>
				<item>
			<title>SQL Server Management: Compatibility Levels</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sql-server-management-compatibility-levels</link>
			<pubDate>Thu, 28 Mar 2013 11:12:00 +0000</pubDate>			<dc:creator>Kevin Conan</dc:creator>
			<category domain="main">Microsoft SQL Server Admin</category>			<guid isPermaLink="false">2165@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;There was a conversation on twitter today about SQL Server Compatibility Levels because someone&amp;#8217;s vendor wanted them to use level 80 (SQL 2000) on a SQL 2012 Instance.  &lt;/p&gt;

&lt;p&gt;There are two issues with what that vendor wanted.  The first is that SQL Server only supports Current Version + 2.  Meaning SQL Server 2012 supports SQL Server 2005 and SQL Server 2008 (and 2008R2).  SQL Server 2008 and 2008R2 have the same major release number (10).  So what this vendor was asking for is not possible because compatibility levels in SQL Server 2012 only go back to 90 (SQL 2005).&lt;/p&gt;

&lt;p&gt;The second (and in my opinion the bigger) issue is why does the vendor want the compatibility level set back at all?  &lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve seen many people who thing that if you set the compatibility level back to a previous version, then everything that worked in that previous version will work now.  For example, they had a SQL 2005 Instance which they migrated to SQL 2012 and they think that setting the compatibility level at 90 means all the discontinued commands will go back to working.&lt;/p&gt;

&lt;p&gt;This is completely incorrect and a dangerous trap!  Compatibility levels are meant to partially run the database in the version you selected while you troubleshoot, fix and then change the compatibility level to the current version.  &lt;/p&gt;

&lt;p&gt;Doing a search on the internet, I cannot find anything directly from Microsoft about what the compatibility levels really do.  However, I&amp;#8217;ve seen and experienced firsthand that they do not allow discontinued code to suddenly work.&lt;/p&gt;

&lt;p&gt;For example, in SQL 2005 you can use a command called &amp;#8220;RAISEERROR&amp;#8221; (note the use of two e&amp;#8217;s in the middle).  If you try that command on a database in SQL 2012 (no matter what compatibility level you have it set at), it will not work because it was discontinued.&lt;/p&gt;

&lt;p&gt;What I&amp;#8217;m trying to say is this, you cannot skip testing and removing discontinued code by using compatibility levels.  You must test, removed discontinued code and work on migrate deprecated code to a supported solution.  It like the old saying &amp;#8220;If something appears too good to be true, it probably is too good to be true&amp;#8221;.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sql-server-management-compatibility-levels&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>There was a conversation on twitter today about SQL Server Compatibility Levels because someone&#8217;s vendor wanted them to use level 80 (SQL 2000) on a SQL 2012 Instance.  </p>

<p>There are two issues with what that vendor wanted.  The first is that SQL Server only supports Current Version + 2.  Meaning SQL Server 2012 supports SQL Server 2005 and SQL Server 2008 (and 2008R2).  SQL Server 2008 and 2008R2 have the same major release number (10).  So what this vendor was asking for is not possible because compatibility levels in SQL Server 2012 only go back to 90 (SQL 2005).</p>

<p>The second (and in my opinion the bigger) issue is why does the vendor want the compatibility level set back at all?  </p>

<p>I&#8217;ve seen many people who thing that if you set the compatibility level back to a previous version, then everything that worked in that previous version will work now.  For example, they had a SQL 2005 Instance which they migrated to SQL 2012 and they think that setting the compatibility level at 90 means all the discontinued commands will go back to working.</p>

<p>This is completely incorrect and a dangerous trap!  Compatibility levels are meant to partially run the database in the version you selected while you troubleshoot, fix and then change the compatibility level to the current version.  </p>

<p>Doing a search on the internet, I cannot find anything directly from Microsoft about what the compatibility levels really do.  However, I&#8217;ve seen and experienced firsthand that they do not allow discontinued code to suddenly work.</p>

<p>For example, in SQL 2005 you can use a command called &#8220;RAISEERROR&#8221; (note the use of two e&#8217;s in the middle).  If you try that command on a database in SQL 2012 (no matter what compatibility level you have it set at), it will not work because it was discontinued.</p>

<p>What I&#8217;m trying to say is this, you cannot skip testing and removing discontinued code by using compatibility levels.  You must test, removed discontinued code and work on migrate deprecated code to a supported solution.  It like the old saying &#8220;If something appears too good to be true, it probably is too good to be true&#8221;.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sql-server-management-compatibility-levels">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sql-server-management-compatibility-levels#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2165</wfw:commentRss>
		</item>
				<item>
			<title>Triggers affect on SQL System Variables</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/triggers-affect-on-sql-system</link>
			<pubDate>Tue, 12 Mar 2013 19:35:00 +0000</pubDate>			<dc:creator>Kevin Conan</dc:creator>
			<category domain="alt">Microsoft SQL Server Admin</category>
<category domain="main">Microsoft SQL Server</category>			<guid isPermaLink="false">2141@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;A while back I ran into an issue where a user was complaining about @@IDENTITY not always returning the value they expected.  &lt;/p&gt;

&lt;p&gt;This was happening on a table that was setup using 3rd party cross database platform replication software.  The software used triggers to capture the changes to the table to send them over to an Oracle table and a DB2 table.  The issue was caused by the trigger inserting records into another table that also had an identity column and that was being returned instead of the one from the original insert.&lt;/p&gt;

&lt;p&gt;I used to also have a debate with a fellow DBA about @@ROWCOUNT.  I use it all the time and haven&amp;#8217;t had any issues.  But I also wanted to know if triggers could affect it.&lt;br /&gt;
Here is some sample code that illustrates how triggers affect @@IDENTITY, @@ROWCOUNT and also demonstrates SCOPE_IDENTITY().&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb10624&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;TABLE&lt;/span&gt; tblTest &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;col1 &lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;IDENTITY&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; NOT NULL, col2 &lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt; NULL&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;TRIGGER&lt;/span&gt; tr_ins_tblTest&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;ON&lt;/span&gt; tblTest&lt;br /&gt;&amp;nbsp;&lt;span style=&quot;color: #0000FF;&quot;&gt;AFTER&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;DECLARE&lt;/span&gt; @&lt;span style=&quot;color: #0000FF;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; @&lt;span style=&quot;color: #0000FF;&quot;&gt;int&lt;/span&gt;&amp;nbsp;= col1&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; inserted;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; tblTest &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;col2&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; @&lt;span style=&quot;color: #0000FF;&quot;&gt;int&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;Inside Trigger 1&#039;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;Where&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,&lt;span style=&quot;color: #FF00FF;&quot;&gt;@@ROWCOUNT&lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;RowCount&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,&lt;span style=&quot;color: #FF00FF;&quot;&gt;@@IDENTITY&lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;Identity&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,&lt;span style=&quot;color: #FF00FF;&quot;&gt;SCOPE_IDENTITY&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;Scope&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;Identity&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #00AF00;&quot;&gt;--really try to mess with @@ROWCOUNT&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; tblTest &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;col2&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;10&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;WHERE&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt; = &lt;span style=&quot;color: #000;&quot;&gt;2&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;Inside Trigger 2&#039;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;Where&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,&lt;span style=&quot;color: #FF00FF;&quot;&gt;@@ROWCOUNT&lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;RowCount&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,&lt;span style=&quot;color: #FF00FF;&quot;&gt;@@IDENTITY&lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;Identity&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,&lt;span style=&quot;color: #FF00FF;&quot;&gt;SCOPE_IDENTITY&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;Scope&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;Identity&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;END&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; tblTest &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;col2&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;10&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;Outside Trigger&#039;&lt;/span&gt;&amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;Where&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,&lt;span style=&quot;color: #FF00FF;&quot;&gt;@@ROWCOUNT&lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;RowCount&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,&lt;span style=&quot;color: #FF00FF;&quot;&gt;@@IDENTITY&lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;Identity&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,&lt;span style=&quot;color: #FF00FF;&quot;&gt;SCOPE_IDENTITY&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;Scope&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;Identity&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;DROP&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;TABLE&lt;/span&gt; tblTest;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb11982&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here is the output from the above code:&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/kconan/reccount.JPG?mtime=1363124071&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/reccount.JPG?mtime=1363124071&quot; width=&quot;327&quot; height=&quot;144&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;So we can see that @@ROWCOUNT is not affected by the trigger.  However we also see that @@IDENTITY can be affected by triggers and the way to get around it is to use SCOPE_IDENTITY() instead.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/triggers-affect-on-sql-system&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>A while back I ran into an issue where a user was complaining about @@IDENTITY not always returning the value they expected.  </p>

<p>This was happening on a table that was setup using 3rd party cross database platform replication software.  The software used triggers to capture the changes to the table to send them over to an Oracle table and a DB2 table.  The issue was caused by the trigger inserting records into another table that also had an identity column and that was being returned instead of the one from the original insert.</p>

<p>I used to also have a debate with a fellow DBA about @@ROWCOUNT.  I use it all the time and haven&#8217;t had any issues.  But I also wanted to know if triggers could affect it.<br />
Here is some sample code that illustrates how triggers affect @@IDENTITY, @@ROWCOUNT and also demonstrates SCOPE_IDENTITY().</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb8543'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb8543','cb61660'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb8543" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> tblTest <span style="color: #808080;">&#40;</span>col1 <span style="color: #0000FF;">INT</span> <span style="color: #0000FF;">IDENTITY</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>,<span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> NOT NULL, col2 <span style="color: #0000FF;">INT</span> NULL<span style="color: #808080;">&#41;</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">GO</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TRIGGER</span> tr_ins_tblTest</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0000FF;">ON</span> tblTest</li><li style="" class="li1">&nbsp;<span style="color: #0000FF;">AFTER</span> <span style="color: #0000FF;">INSERT</span></li><li style="" class="li2"><span style="color: #0000FF;">AS</span> </li><li style="" class="li1"><span style="color: #0000FF;">BEGIN</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0000FF;">DECLARE</span> @<span style="color: #0000FF;">int</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">INT</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span> @<span style="color: #0000FF;">int</span>&nbsp;= col1</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span> inserted;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> tblTest <span style="color: #808080;">&#40;</span>col2<span style="color: #808080;">&#41;</span> </li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span> @<span style="color: #0000FF;">int</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp;<span style="color: #FF0000;">'Inside Trigger 1'</span>&nbsp;<span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Where</span><span style="color: #808080;">&#93;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<span style="color: #FF00FF;">@@ROWCOUNT</span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">RowCount</span><span style="color: #808080;">&#93;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<span style="color: #FF00FF;">@@IDENTITY</span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Identity</span><span style="color: #808080;">&#93;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<span style="color: #FF00FF;">SCOPE_IDENTITY</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span>&nbsp; &nbsp;<span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Scope</span> <span style="color: #0000FF;">Identity</span><span style="color: #808080;">&#93;</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #00AF00;">--really try to mess with @@ROWCOUNT</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> tblTest <span style="color: #808080;">&#40;</span>col2<span style="color: #808080;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span> <span style="color: #000;">10</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> <span style="color: #000;">1</span> = <span style="color: #000;">2</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp;<span style="color: #FF0000;">'Inside Trigger 2'</span>&nbsp;<span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Where</span><span style="color: #808080;">&#93;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<span style="color: #FF00FF;">@@ROWCOUNT</span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">RowCount</span><span style="color: #808080;">&#93;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<span style="color: #FF00FF;">@@IDENTITY</span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Identity</span><span style="color: #808080;">&#93;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<span style="color: #FF00FF;">SCOPE_IDENTITY</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span>&nbsp; &nbsp;<span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Scope</span> <span style="color: #0000FF;">Identity</span><span style="color: #808080;">&#93;</span>;</li><li style="" class="li2">&nbsp; &nbsp; </li><li style="" class="li1"><span style="color: #0000FF;">END</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">GO</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> tblTest <span style="color: #808080;">&#40;</span>col2<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'10'</span><span style="color: #808080;">&#41;</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp;<span style="color: #FF0000;">'Outside Trigger'</span>&nbsp; <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Where</span><span style="color: #808080;">&#93;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; ,<span style="color: #FF00FF;">@@ROWCOUNT</span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">RowCount</span><span style="color: #808080;">&#93;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; ,<span style="color: #FF00FF;">@@IDENTITY</span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Identity</span><span style="color: #808080;">&#93;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; ,<span style="color: #FF00FF;">SCOPE_IDENTITY</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span>&nbsp; &nbsp;<span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Scope</span> <span style="color: #0000FF;">Identity</span><span style="color: #808080;">&#93;</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">TABLE</span> tblTest;</li></ol></div><div id="cb61660" style="display: none; color: red;"></div></div></div>

<p>Here is the output from the above code:</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/kconan/reccount.JPG?mtime=1363124071"><img alt="" src="http://blogs.lessthandot.com/media/users/kconan/reccount.JPG?mtime=1363124071" width="327" height="144" /></a></div>

<p>So we can see that @@ROWCOUNT is not affected by the trigger.  However we also see that @@IDENTITY can be affected by triggers and the way to get around it is to use SCOPE_IDENTITY() instead.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/triggers-affect-on-sql-system">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/triggers-affect-on-sql-system#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2141</wfw:commentRss>
		</item>
				<item>
			<title>Using SELECT * in views gotcha</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/using-select-in-views-gotcha</link>
			<pubDate>Tue, 12 Mar 2013 12:06:00 +0000</pubDate>			<dc:creator>Kevin Conan</dc:creator>
			<category domain="alt">Database Administration</category>
<category domain="main">Microsoft SQL Server Admin</category>			<guid isPermaLink="false">2140@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;If ever a DBA walked up a mountain and came back down with two stones that had 10 commandments written on them, &amp;#8220;thou shalt not use SELECT *&amp;#8221; would be one of them.  However, that same DBA would turn around and within 5 minutes use it themselves!&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/kconan/moses.JPG?mtime=1363096883&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/moses.JPG?mtime=1363096883&quot; width=&quot;233&quot; height=&quot;311&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;One place that DBAs use SELECT * is when they create views.  The idea is that you do actually want every column available to the view because the query that hits that view should limit which columns it wants returned.&lt;/p&gt;

&lt;p&gt;This works, but there is one big issue with it that most people learn the hard way.  If the schema of the source table that the view is selecting from changes, the view will NOT automatically update to include those changes.&lt;/p&gt;

&lt;p&gt;For example, let&amp;#8217;s create a simple table with some data and a view over it (because we are using really simple code, I&amp;#8217;m not going format visually the way I normally do).&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb99938&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;TABLE&lt;/span&gt; tblViewExample &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;col1 &lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt; NULL&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VIEW&lt;/span&gt; vViewExample &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; * &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; tblViewExample&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; vViewExample &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;col1&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; vViewExample &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;col1&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; vViewExample &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;col1&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; * &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; vViewExample;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb50452&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/kconan/view1.JPG?mtime=1363096883&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/view1.JPG?mtime=1363096883&quot; width=&quot;67&quot; height=&quot;83&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;I did break the rule of no SELECT * again but it&amp;#8217;s to demonstrate the point of this article.&lt;br /&gt;
So far everything is being returned as we expect it.  Now let&amp;#8217;s change the schema of our table and see what happens.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb89257&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;ALTER&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;TABLE&lt;/span&gt; tblViewExample &lt;span style=&quot;color: #0000FF;&quot;&gt;ADD&lt;/span&gt; col2 &lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt; NULL;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;UPDATE&lt;/span&gt; tblViewExample &lt;span style=&quot;color: #0000FF;&quot;&gt;SET&lt;/span&gt; col2 = col1 * &lt;span style=&quot;color: #000;&quot;&gt;5&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; * &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; vViewExample;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb98984&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/kconan/view1.JPG?mtime=1363096883&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/view1.JPG?mtime=1363096883&quot; width=&quot;67&quot; height=&quot;83&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;Notice that col2 is missing even though the view is using SELECT *.  Let&amp;#8217;s see what happens if we try to use the view to insert a new record with data in col2.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb12895&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; vViewExample &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;col1, col2&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: #000;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb71142&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/kconan/view2.JPG?mtime=1363096883&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/view2.JPG?mtime=1363096883&quot; width=&quot;245&quot; height=&quot;38&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;To fix the &amp;#8220;broken&amp;#8221; view, we have to rebuild it.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb13722&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;DROP&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VIEW&lt;/span&gt; vViewExample;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VIEW&lt;/span&gt; vViewExample &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; * &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; tblViewExample&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb5843&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now let&amp;#8217;s try the insert statement again and then the select statement.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb3945&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; vViewExample &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;col1, col2&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: #000;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; * &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; vViewExample;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb35572&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/kconan/view3.JPG?mtime=1363096883&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/view3.JPG?mtime=1363096883&quot; width=&quot;108&quot; height=&quot;102&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;And of course, let&amp;#8217;s clean up after ourselves!&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb78852&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;DROP&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VIEW&lt;/span&gt; vViewExample;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;DROP&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;TABLE&lt;/span&gt; tblViewExample;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb50140&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/using-select-in-views-gotcha&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>If ever a DBA walked up a mountain and came back down with two stones that had 10 commandments written on them, &#8220;thou shalt not use SELECT *&#8221; would be one of them.  However, that same DBA would turn around and within 5 minutes use it themselves!</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/kconan/moses.JPG?mtime=1363096883"><img alt="" src="http://blogs.lessthandot.com/media/users/kconan/moses.JPG?mtime=1363096883" width="233" height="311" /></a></div>

<p>One place that DBAs use SELECT * is when they create views.  The idea is that you do actually want every column available to the view because the query that hits that view should limit which columns it wants returned.</p>

<p>This works, but there is one big issue with it that most people learn the hard way.  If the schema of the source table that the view is selecting from changes, the view will NOT automatically update to include those changes.</p>

<p>For example, let&#8217;s create a simple table with some data and a view over it (because we are using really simple code, I&#8217;m not going format visually the way I normally do).</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb92964'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb92964','cb7392'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb92964" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> tblViewExample <span style="color: #808080;">&#40;</span>col1 <span style="color: #0000FF;">INT</span> NULL<span style="color: #808080;">&#41;</span>;</li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li><li style="" class="li1"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">VIEW</span> vViewExample <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">SELECT</span> * <span style="color: #0000FF;">FROM</span> tblViewExample</li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> vViewExample <span style="color: #808080;">&#40;</span>col1<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span>;</li><li style="" class="li2"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> vViewExample <span style="color: #808080;">&#40;</span>col1<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">2</span><span style="color: #808080;">&#41;</span>;</li><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> vViewExample <span style="color: #808080;">&#40;</span>col1<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">3</span><span style="color: #808080;">&#41;</span>;</li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> * <span style="color: #0000FF;">FROM</span> vViewExample;</li></ol></div><div id="cb7392" style="display: none; color: red;"></div></div></div>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/kconan/view1.JPG?mtime=1363096883"><img alt="" src="http://blogs.lessthandot.com/media/users/kconan/view1.JPG?mtime=1363096883" width="67" height="83" /></a></div>

<p>I did break the rule of no SELECT * again but it&#8217;s to demonstrate the point of this article.<br />
So far everything is being returned as we expect it.  Now let&#8217;s change the schema of our table and see what happens.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb54963'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb54963','cb73089'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb54963" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">TABLE</span> tblViewExample <span style="color: #0000FF;">ADD</span> col2 <span style="color: #0000FF;">INT</span> NULL;</li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li><li style="" class="li1"><span style="color: #0000FF;">UPDATE</span> tblViewExample <span style="color: #0000FF;">SET</span> col2 = col1 * <span style="color: #000;">5</span>;</li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> * <span style="color: #0000FF;">FROM</span> vViewExample;</li></ol></div><div id="cb73089" style="display: none; color: red;"></div></div></div>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/kconan/view1.JPG?mtime=1363096883"><img alt="" src="http://blogs.lessthandot.com/media/users/kconan/view1.JPG?mtime=1363096883" width="67" height="83" /></a></div>

<p>Notice that col2 is missing even though the view is using SELECT *.  Let&#8217;s see what happens if we try to use the view to insert a new record with data in col2.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb38012'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb38012','cb89345'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb38012" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> vViewExample <span style="color: #808080;">&#40;</span>col1, col2<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">5</span>, <span style="color: #000;">5</span><span style="color: #808080;">&#41;</span>;</li></ol></div><div id="cb89345" style="display: none; color: red;"></div></div></div>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/kconan/view2.JPG?mtime=1363096883"><img alt="" src="http://blogs.lessthandot.com/media/users/kconan/view2.JPG?mtime=1363096883" width="245" height="38" /></a></div>

<p>To fix the &#8220;broken&#8221; view, we have to rebuild it.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb5368'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb5368','cb37225'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb5368" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">VIEW</span> vViewExample;</li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li><li style="" class="li1"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">VIEW</span> vViewExample <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">SELECT</span> * <span style="color: #0000FF;">FROM</span> tblViewExample</li></ol></div><div id="cb37225" style="display: none; color: red;"></div></div></div>

<p>Now let&#8217;s try the insert statement again and then the select statement.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb6001'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb6001','cb44500'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb6001" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> vViewExample <span style="color: #808080;">&#40;</span>col1, col2<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">5</span>, <span style="color: #000;">5</span><span style="color: #808080;">&#41;</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> * <span style="color: #0000FF;">FROM</span> vViewExample;</li></ol></div><div id="cb44500" style="display: none; color: red;"></div></div></div>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/kconan/view3.JPG?mtime=1363096883"><img alt="" src="http://blogs.lessthandot.com/media/users/kconan/view3.JPG?mtime=1363096883" width="108" height="102" /></a></div>

<p>And of course, let&#8217;s clean up after ourselves!</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb77990'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb77990','cb86301'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb77990" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">VIEW</span> vViewExample;</li><li style="" class="li2"><span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">TABLE</span> tblViewExample;</li></ol></div><div id="cb86301" style="display: none; color: red;"></div></div></div><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/using-select-in-views-gotcha">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/using-select-in-views-gotcha#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2140</wfw:commentRss>
		</item>
				<item>
			<title>SSMS - Enabling Ctrl+R Shortcut to show or hide query results/messages pane</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/ssms-enabling-ctrl-r-shortcut</link>
			<pubDate>Mon, 04 Mar 2013 14:58:00 +0000</pubDate>			<dc:creator>Kevin Conan</dc:creator>
			<category domain="main">Microsoft SQL Server</category>			<guid isPermaLink="false">2133@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Do you use Ctrl+R to hide or display the query results/messages pane in SSMS?  Have you installed SSMS 2012 and find that it does not work?  Does it drive you crazy because you think they pulled keyboard shortcut or because in some installs it works but not in others?&lt;/p&gt;

&lt;p&gt;Fear not, you can add this keyboard short-cut!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;In SSMS open the &amp;#8220;Tools&amp;#8221; menu and choose &amp;#8220;Options&amp;#8230;&amp;#8221;.&lt;/li&gt;
  &lt;li&gt;On the left, expand &amp;#8220;Environment&amp;#8221;, then expand &amp;#8220;Keyboard&amp;#8221; and then click on &amp;#8220;Keyboard&amp;#8221;.&lt;/li&gt;
  &lt;li&gt;Choose &amp;#8220;Window.ShowResultsPane&amp;#8221; (you can type that into the &amp;#8220;Show commands containing:&amp;#8221; field to find it faster.  Choose &amp;#8220;SQL Query Editor&amp;#8221; from the &amp;#8220;Use new shortcut in:&amp;#8221; drop down list.&lt;/li&gt;
  &lt;li&gt;Click into the &amp;#8220;Press shortcut keys:&amp;#8221; field and press Ctrl and R at the same time (the field should update to show &amp;#8220;Ctrl +R&amp;#8221;.&lt;/li&gt;  
  &lt;li&gt;Review the &amp;#8220;Shortcut currently used by:&amp;#8221; dropdown list to ensure there are no other short cuts using Ctrl +R for SQL Query Editor.&lt;/li&gt;
  &lt;li&gt;Click the Assign button and then the OK button.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/kconan/SSMSCtrlRSettings.JPG?mtime=1362416270&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/SSMSCtrlRSettings.JPG?mtime=1362416270&quot; width=&quot;644&quot; height=&quot;376&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;And presto, the Ctrl+R functionality to hide or display the query results/messages pane in SSMS!&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/ssms-enabling-ctrl-r-shortcut&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Do you use Ctrl+R to hide or display the query results/messages pane in SSMS?  Have you installed SSMS 2012 and find that it does not work?  Does it drive you crazy because you think they pulled keyboard shortcut or because in some installs it works but not in others?</p>

<p>Fear not, you can add this keyboard short-cut!</p>

<ol>
  <li>In SSMS open the &#8220;Tools&#8221; menu and choose &#8220;Options&#8230;&#8221;.</li>
  <li>On the left, expand &#8220;Environment&#8221;, then expand &#8220;Keyboard&#8221; and then click on &#8220;Keyboard&#8221;.</li>
  <li>Choose &#8220;Window.ShowResultsPane&#8221; (you can type that into the &#8220;Show commands containing:&#8221; field to find it faster.  Choose &#8220;SQL Query Editor&#8221; from the &#8220;Use new shortcut in:&#8221; drop down list.</li>
  <li>Click into the &#8220;Press shortcut keys:&#8221; field and press Ctrl and R at the same time (the field should update to show &#8220;Ctrl +R&#8221;.</li>  
  <li>Review the &#8220;Shortcut currently used by:&#8221; dropdown list to ensure there are no other short cuts using Ctrl +R for SQL Query Editor.</li>
  <li>Click the Assign button and then the OK button.</li>
</ol>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/kconan/SSMSCtrlRSettings.JPG?mtime=1362416270"><img alt="" src="http://blogs.lessthandot.com/media/users/kconan/SSMSCtrlRSettings.JPG?mtime=1362416270" width="644" height="376" /></a></div>

<p>And presto, the Ctrl+R functionality to hide or display the query results/messages pane in SSMS!</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/ssms-enabling-ctrl-r-shortcut">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/ssms-enabling-ctrl-r-shortcut#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2133</wfw:commentRss>
		</item>
				<item>
			<title>SSRS - Micro Adjustments with the Arrow Keys</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/ssrs/ssrs-micro-adjustments-with-the</link>
			<pubDate>Tue, 26 Feb 2013 16:06:00 +0000</pubDate>			<dc:creator>Kevin Conan</dc:creator>
			<category domain="main">SSRS</category>
<category domain="alt">Business Intelligence</category>			<guid isPermaLink="false">2126@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Does it every bother you when you use the Arrow Keys to move an object in your SSRS report that it jumps much further over than you really wanted?  Maybe you just wanted to nudge it a few pixels to the left but instead it is now over lapping the next object.&lt;/p&gt;

&lt;p&gt;I used to think that I had to either use my mouse to move it over or start playing with the position coordinates in the properties of the object.&lt;/p&gt;

&lt;p&gt;NOT ANYMORE!&lt;/p&gt;

&lt;p&gt;To make micro adjustments using the Arrow Keys, simply hold down the Ctrl Key at the same time.&lt;/p&gt;

&lt;p&gt;It may seem odd to post such a simple and short article, but this little tip saves me a fair amount of time and swearing at my computer.  I hope it does the same for you as well!&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/ssrs/ssrs-micro-adjustments-with-the&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Does it every bother you when you use the Arrow Keys to move an object in your SSRS report that it jumps much further over than you really wanted?  Maybe you just wanted to nudge it a few pixels to the left but instead it is now over lapping the next object.</p>

<p>I used to think that I had to either use my mouse to move it over or start playing with the position coordinates in the properties of the object.</p>

<p>NOT ANYMORE!</p>

<p>To make micro adjustments using the Arrow Keys, simply hold down the Ctrl Key at the same time.</p>

<p>It may seem odd to post such a simple and short article, but this little tip saves me a fair amount of time and swearing at my computer.  I hope it does the same for you as well!</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/ssrs/ssrs-micro-adjustments-with-the">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/ssrs/ssrs-micro-adjustments-with-the#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2126</wfw:commentRss>
		</item>
				<item>
			<title>SQL Server Licensing for Non-Production</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/sql-server-licensing-for-non-1</link>
			<pubDate>Thu, 14 Feb 2013 12:25:00 +0000</pubDate>			<dc:creator>Kevin Conan</dc:creator>
			<category domain="main">Microsoft SQL Server</category>			<guid isPermaLink="false">2105@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;One of my favorite movie quotes comes from Under Siege 2 (slightly altered to avoid cursing):  &amp;#8220;Assumption is the mother of all screw ups&amp;#8221;.&lt;/p&gt;

&lt;p&gt;Before we go any further, if you are ever unsure about SQL Server Licensing, contact Microsoft (1-800-426-9400 open Monday through Friday 6:00 AM PST to 6:00 PM PST).  What is valid for me at this point in time may not be valid for you or even for myself at a different point in time.&lt;/p&gt;

&lt;h1&gt;The Back Story&lt;/h1&gt;

&lt;p&gt;One of my most recent &amp;#8220;egg on my face&amp;#8221; moments came from a discussion on twitter about SQL Server licensing in non-production environments.  A question came in on the #sqlhelp hashtag asking about a situation where the QA group at their company installed Enterprise Edition and the person wanted to know if they had to uninstall it and reinstall Developer Edition to be compliant with licensing.  &lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://www.flickr.com/photos/xurble/376588066/&quot;&gt;&lt;img alt=&quot;court&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/neon question mark.jpg?mtime=1360851095&quot; width=&quot;300&quot; height=&quot;300&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;At a previous company that I worked for, I was always told by the Database Manager that if the system was non-production, licensing was free.  So I chimed into the twitter conversation and was then challenged by Robert Davis (&lt;a href=&quot;https://twitter.com/SQLSoldier&quot;&gt;T&lt;/a&gt;|&lt;a href=&quot;http://www.sqlsoldier.com &quot;&gt;B&lt;/a&gt;) that it should be verified by a licensing expert.  He challenged it based on that Enterprise Agreements can override regular licensing.  My previous employer had an Enterprise Agreement and my current one does not.&lt;/p&gt;

&lt;h1&gt;1st Assumption&lt;/h1&gt;

&lt;p&gt;My first assumption was that the licensing rules that applied to my previous employer would carry over to my current employer.  The problem with that assumption is something I already pointed out, one had an Enterprise Agreement and one did not.  So I really was not comparing apples to apples.&lt;/p&gt;

&lt;p&gt;Now I too had a stake in finding the correct answer this licensing question.  So I offered to the conversation to contact the licensing expert at the vendor from which my current employer purchases their licenses from.  After a couple of e-mails back and forth we had a mostly clear answer that because the production workflows never touch the non-production SQL Instances, you were indeed covered by the production licenses and did not need extra ones.  This turned out to NOT be true.&lt;/p&gt;

&lt;h1&gt;2nd Assumption&lt;/h1&gt;

&lt;p&gt;My second assumption was that someone who didn&amp;#8217;t work directly from Microsoft can 100% be trusted with licensing questions.  SQL Server Licensing is well known for being complex and very difficult to understand.  I do not blame or think less of our software vendor for coming back with the wrong answer because I&amp;#8217;m sure my preconceived thoughts on what the right answer is swayed them.&lt;/p&gt;

&lt;p&gt;I replied back on the twitter conversation with what I talked about with my vendor.  Fortunately Steinar Anderson (&lt;a href=&quot;https://twitter.com/SQLSteinar&quot;&gt;T&lt;/a&gt;|&lt;a href=&quot;http://www.sqlservice.se/blogg &quot;&gt;B&lt;/a&gt;) challenged me again to go straight to Microsoft to verify what the correct answer is.&lt;/p&gt;

&lt;h1&gt;The truth (for my situation)&lt;/h1&gt;

&lt;p&gt;I called Microsoft&amp;#8217;s Licensing and was able to get ahold of someone with a couple minutes and they told me that unless you have an Enterprise Agreement, Microsoft does not look at production and non-production differently.  You have to license each one.  For the non-production SQL Instances you can use Developer Edition but must have a license of it purchased for each person who will use any of the Developer Edition SQL Instances.&lt;/p&gt;

&lt;p&gt;So now I will leave you with two of the favorite DBA sayings about Licensing: &amp;#8220;It depends&amp;#8221; and &amp;#8220;Always confirm with Microsoft about your licensing situation&amp;#8221;.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/sql-server-licensing-for-non-1&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>One of my favorite movie quotes comes from Under Siege 2 (slightly altered to avoid cursing):  &#8220;Assumption is the mother of all screw ups&#8221;.</p>

<p>Before we go any further, if you are ever unsure about SQL Server Licensing, contact Microsoft (1-800-426-9400 open Monday through Friday 6:00 AM PST to 6:00 PM PST).  What is valid for me at this point in time may not be valid for you or even for myself at a different point in time.</p>

<h1>The Back Story</h1>

<p>One of my most recent &#8220;egg on my face&#8221; moments came from a discussion on twitter about SQL Server licensing in non-production environments.  A question came in on the #sqlhelp hashtag asking about a situation where the QA group at their company installed Enterprise Edition and the person wanted to know if they had to uninstall it and reinstall Developer Edition to be compliant with licensing.  </p>

<div class="image_block"><a href="http://www.flickr.com/photos/xurble/376588066/"><img alt="court" src="http://blogs.lessthandot.com/media/users/kconan/neon question mark.jpg?mtime=1360851095" width="300" height="300" /></a></div>

<p>At a previous company that I worked for, I was always told by the Database Manager that if the system was non-production, licensing was free.  So I chimed into the twitter conversation and was then challenged by Robert Davis (<a href="https://twitter.com/SQLSoldier">T</a>|<a href="http://www.sqlsoldier.com ">B</a>) that it should be verified by a licensing expert.  He challenged it based on that Enterprise Agreements can override regular licensing.  My previous employer had an Enterprise Agreement and my current one does not.</p>

<h1>1st Assumption</h1>

<p>My first assumption was that the licensing rules that applied to my previous employer would carry over to my current employer.  The problem with that assumption is something I already pointed out, one had an Enterprise Agreement and one did not.  So I really was not comparing apples to apples.</p>

<p>Now I too had a stake in finding the correct answer this licensing question.  So I offered to the conversation to contact the licensing expert at the vendor from which my current employer purchases their licenses from.  After a couple of e-mails back and forth we had a mostly clear answer that because the production workflows never touch the non-production SQL Instances, you were indeed covered by the production licenses and did not need extra ones.  This turned out to NOT be true.</p>

<h1>2nd Assumption</h1>

<p>My second assumption was that someone who didn&#8217;t work directly from Microsoft can 100% be trusted with licensing questions.  SQL Server Licensing is well known for being complex and very difficult to understand.  I do not blame or think less of our software vendor for coming back with the wrong answer because I&#8217;m sure my preconceived thoughts on what the right answer is swayed them.</p>

<p>I replied back on the twitter conversation with what I talked about with my vendor.  Fortunately Steinar Anderson (<a href="https://twitter.com/SQLSteinar">T</a>|<a href="http://www.sqlservice.se/blogg ">B</a>) challenged me again to go straight to Microsoft to verify what the correct answer is.</p>

<h1>The truth (for my situation)</h1>

<p>I called Microsoft&#8217;s Licensing and was able to get ahold of someone with a couple minutes and they told me that unless you have an Enterprise Agreement, Microsoft does not look at production and non-production differently.  You have to license each one.  For the non-production SQL Instances you can use Developer Edition but must have a license of it purchased for each person who will use any of the Developer Edition SQL Instances.</p>

<p>So now I will leave you with two of the favorite DBA sayings about Licensing: &#8220;It depends&#8221; and &#8220;Always confirm with Microsoft about your licensing situation&#8221;.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/sql-server-licensing-for-non-1">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/sql-server-licensing-for-non-1#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2105</wfw:commentRss>
		</item>
				<item>
			<title>SSRS - Linking one report to another report</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/ssrs/ssrs-linking-one-report-to</link>
			<pubDate>Wed, 13 Feb 2013 18:09:00 +0000</pubDate>			<dc:creator>Kevin Conan</dc:creator>
			<category domain="main">SSRS</category>
<category domain="alt">Business Intelligence</category>			<guid isPermaLink="false">2101@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;When creating reports, I try to keep them simple, clean and with as little information as possible.  What I mean by as little information as possible is that I try to keep the information summarized so that the value of the report isn&amp;#8217;t lost in a sea of details.  However, for some reports you still need those details to back up the summary and to allow for digging deeper into issues.&lt;/p&gt;

&lt;p&gt;What I have found works well is to add links in the summary report to the detail report.  This approach allows us to pass in parameters to it and still limit the detail report to just the information that is needed.  &lt;/p&gt;

&lt;p&gt;To create a link in a report, you go to the Text Box Properties of the text box that you want to be the link, choose Action on the left side and then the &amp;#8220;Go to report&amp;#8221; radio button option.  &lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/kconan/SSRS - action.JPG?mtime=1360785989&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/SSRS - action.JPG?mtime=1360785989&quot; width=&quot;580&quot; height=&quot;525&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;If you are using Visual Studio, the dropdown list under &amp;#8220;Specify a report&amp;#8221; will be populated with included reports in your project.  You can also use the expression builder to key in the name of the report you are linking to.  The name you key in is the published report name and the .rdl file name.  This screen also allows you to specify what parameters you want to pass into the detail report.&lt;/p&gt;

&lt;p&gt;When you publish the summary and detail reports, if you publish them to the same directory then the summary report will automatically find the detail report when the link is clicked.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/ssrs/ssrs-linking-one-report-to&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>When creating reports, I try to keep them simple, clean and with as little information as possible.  What I mean by as little information as possible is that I try to keep the information summarized so that the value of the report isn&#8217;t lost in a sea of details.  However, for some reports you still need those details to back up the summary and to allow for digging deeper into issues.</p>

<p>What I have found works well is to add links in the summary report to the detail report.  This approach allows us to pass in parameters to it and still limit the detail report to just the information that is needed.  </p>

<p>To create a link in a report, you go to the Text Box Properties of the text box that you want to be the link, choose Action on the left side and then the &#8220;Go to report&#8221; radio button option.  </p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/kconan/SSRS - action.JPG?mtime=1360785989"><img alt="" src="http://blogs.lessthandot.com/media/users/kconan/SSRS - action.JPG?mtime=1360785989" width="580" height="525" /></a></div>

<p>If you are using Visual Studio, the dropdown list under &#8220;Specify a report&#8221; will be populated with included reports in your project.  You can also use the expression builder to key in the name of the report you are linking to.  The name you key in is the published report name and the .rdl file name.  This screen also allows you to specify what parameters you want to pass into the detail report.</p>

<p>When you publish the summary and detail reports, if you publish them to the same directory then the summary report will automatically find the detail report when the link is clicked.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/ssrs/ssrs-linking-one-report-to">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/ssrs/ssrs-linking-one-report-to#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2101</wfw:commentRss>
		</item>
				<item>
			<title>Getting SSRS Subscriptions for a Specific Date</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/ssrs/getting-ssrs-subscriptions-for-a</link>
			<pubDate>Tue, 20 Nov 2012 20:32:00 +0000</pubDate>			<dc:creator>Kevin Conan</dc:creator>
			<category domain="alt">Microsoft SQL Server Admin</category>
<category domain="main">SSRS</category>			<guid isPermaLink="false">1901@http://blogs.lessthandot.com/</guid>
						<description>&lt;h2&gt;The Back Story&lt;/h2&gt;


&lt;p&gt;This past weekend, work was being done on our exchange server, so e-mail was down most of Saturday.  What everyone (myself included) failed to realize was that this was going to impact scheduled reports from SSRS.&lt;/p&gt;

&lt;p&gt;So Monday morning, I got an e-mail asking about which reports should have ran on the Saturday and who they would have gone to.&lt;/p&gt;

&lt;p&gt;It sounds like such a simple request that I figured it couldn&#039;t be that hard to figure it out.  I was dead wrong.  &lt;/p&gt;


&lt;h2&gt;The Hurdles&lt;/h2&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/kconan/hurdles.jpg?mtime=1353450411&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/hurdles.jpg?mtime=1353450411&quot; width=&quot;400&quot; height=&quot;338&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;After poking around in SSRS Web Interface, I quickly found that short of opening each and every subscription there was no way to find this information. Next I took a peek in the ReportServer database where SSRS is hosted and it looked pretty simple.  I peeked in a few tables and the column names all lined up nice for joining to the other tables.  But then I saw the first of two hurdles that wouldn&#039;t be so easy to get past.&lt;/p&gt;


&lt;h2&gt;Subscriptions.ExtensionSettings&lt;/h2&gt;


&lt;p&gt;I found the e-mail addresses that each Subscription is e-mailed to.  The problem (or opportunity) is that it is buried in an XML field - Subscriptions.ExtensionSettings.  This is the first opportunity that I&#039;ve really had to mess with XML in SQL in a long time so I figured it wouldn&#039;t be too bad and I could figure out how to pluck what I needed.&lt;/p&gt;

&lt;p&gt;However, my heart sank when I hit the second hurdle.  &lt;/p&gt;


&lt;h2&gt;Schedule.RecurrenceType, Schedule.DaysOfWeek and Schedule.DaysOfMonth&lt;/h2&gt;


&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/kconan/SSRS_Schedule.JPG?mtime=1353450271&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/SSRS_Schedule.JPG?mtime=1353450271&quot; width=&quot;505&quot; height=&quot;136&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;The Schedule table has a series of fields where it stores the schedule - Schedule.RecurrenceType, Schedule.DaysOfWeek and Schedule.DaysOfMonth.  This one wasn&#039;t going to be as straight forward to get past.  I remember something in the back of my mind about taking a number have to square it or something or another but it was all really fuzzy.&lt;/p&gt;


&lt;h2&gt;This can&#039;t be the first time someone has had to solve this issue, who&#039;s got a blog or forum post about it?!?!&lt;/h2&gt;


&lt;p&gt;At this point, I figured it was time to turn to the web.  This has to be an issue that others have come across, so how did they solve it?  After searching around for a while, I wasn&#039;t able to find anyone who broke down the schedule fields.  In fact, the only responses from Microsoft on their forums was that they don&#039;t support querying them!  It was time for some bigger guns so I turned to twitter and posted on #SQLHELP and #SSRSHELP.  &lt;/p&gt;

&lt;p&gt;After a little while and a couple of conversations, people gave me the idea of linking the Schedules to their jobs and pulling the schedules that way.  Linking the Schedules to their Jobs was easy.  However, the job schedules are also difficult to figure out because they are done in a similar way.&lt;/p&gt;


&lt;h2&gt;Ah, there&#039;s light at the end of this tunnel!&lt;/h2&gt;


&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/kconan/tunnel.jpg?mtime=1353450579&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/tunnel.jpg?mtime=1353450579&quot; width=&quot;300&quot; height=&quot;224&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;The difference between job schedules and subscription schedules is that there ARE posts out there on how to decipher them!  Between the little I was able to find about the schedules and the information about the job schedules, now I had what I needed to decipher the Subscription Schedules.&lt;/p&gt;

&lt;p&gt;Remember, I needed to know what report subscriptions should have ran on a specific day.&lt;/p&gt;

&lt;p&gt;Schedule.RecurrenceType had 3 values that I needed:&lt;/p&gt;

&lt;p&gt;2 - The subscription runs multiple times during the day, every day.  So I want all subscriptions that have that setting.&lt;br /&gt;
4 - The subscription runs one or more days a week.  This is used in conjunction with Schedule.DaysOfWeek.&lt;br /&gt;
5 - The subscription runs on specific days of the month.  This is used in conjunction with Schedule.DaysOfMonth.&lt;/p&gt;

&lt;p&gt;I&#039;m not going to explain bit wise, but here is a link to a BOL Article:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms174965.aspx&quot;&gt;http://msdn.microsoft.com/en-us/library/ms174965.aspx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Schedule.DaysOfWeek and Schedule.DaysOfMonth work off a bit checker (bit wise).  It&#039;ll help if you think of the day of the week in terms of what number it is.  For example, Sunday = 1, Monday = 2, Tuesday = 3 etc.&lt;/p&gt;

&lt;p&gt;The first value (Sunday and the first of the month) use a bit value of 1.  After that you can figure out the bit value by taking 2 the power of the number you are looking for minus 1.  For example, for the 3rd, it would be 2 to the power of (3 - 1) which is 2 to the power of 2 which equals 4.&lt;/p&gt;

&lt;p&gt;So if we were looking for reports that ran on every Tuesday, the TSQL would be Schedule.RecurrenceType = 4 AND Schedule.DaysofWeek &amp;amp; 4 = 4.&lt;/p&gt;


&lt;h2&gt;The Query&lt;/h2&gt;


&lt;p&gt;I cleaned up the query a little bit by having a variable called @Date that you would set to the date you want to know which subscriptions would have been run on.&lt;/p&gt;

&lt;p&gt;The query returns the Path to the Report, the Report Name, the owner of the Subscription and which E-Mail addresses it would have been sent to.&lt;/p&gt;

&lt;p&gt;This by no means a finished and completely polished query, but rather a good starting point for others to use for their purposes.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb65702&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;DECLARE&lt;/span&gt;&amp;nbsp; @&lt;span style=&quot;color: #0000FF;&quot;&gt;Date&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;DATETIME&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,@DaysOfWeek&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,@DaysOfMonth&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SET&lt;/span&gt; @&lt;span style=&quot;color: #0000FF;&quot;&gt;Date&lt;/span&gt;&amp;nbsp; &amp;nbsp;= &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2012-11-17 00:00:00.000&#039;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; @DaysOfWeek&amp;nbsp; = &lt;span style=&quot;color: #0000FF;&quot;&gt;CASE&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;DATEPART&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DW,@&lt;span style=&quot;color: #0000FF;&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&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; &lt;span style=&quot;color: #0000FF;&quot;&gt;WHEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;THEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;--Sunday&lt;/span&gt;&lt;br /&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; &lt;span style=&quot;color: #0000FF;&quot;&gt;WHEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;THEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;2&lt;/span&gt; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;--Monday&lt;/span&gt;&lt;br /&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; &lt;span style=&quot;color: #0000FF;&quot;&gt;WHEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;THEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;4&lt;/span&gt; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;--Tuesday&lt;/span&gt;&lt;br /&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; &lt;span style=&quot;color: #0000FF;&quot;&gt;WHEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;4&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;THEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;8&lt;/span&gt; &amp;nbsp;&lt;span style=&quot;color: #00AF00;&quot;&gt;--Wednesday&lt;/span&gt;&lt;br /&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; &lt;span style=&quot;color: #0000FF;&quot;&gt;WHEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;THEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;16&lt;/span&gt; &lt;span style=&quot;color: #00AF00;&quot;&gt;--Thursday&lt;/span&gt;&lt;br /&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; &lt;span style=&quot;color: #0000FF;&quot;&gt;WHEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;THEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;32&lt;/span&gt; &lt;span style=&quot;color: #00AF00;&quot;&gt;--Friday&lt;/span&gt;&lt;br /&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; &lt;span style=&quot;color: #0000FF;&quot;&gt;WHEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;THEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;64&lt;/span&gt; &lt;span style=&quot;color: #00AF00;&quot;&gt;--Saturday&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;END&lt;/span&gt;;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&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; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; @DaysOfMonth&amp;nbsp;= &lt;span style=&quot;color: #0000FF;&quot;&gt;CASE&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;DATEPART&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;D,@&lt;span style=&quot;color: #0000FF;&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&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; &lt;span style=&quot;color: #0000FF;&quot;&gt;WHEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;THEN&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;&lt;br /&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; &lt;span style=&quot;color: #0000FF;&quot;&gt;ELSE&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;POWER&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;DATEPART&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;D,@&lt;span style=&quot;color: #0000FF;&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; - &lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;END&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;DISTINCT&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SUB.&lt;span style=&quot;color: #202020;&quot;&gt;ReportPath&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,SUB.&lt;span style=&quot;color: #202020;&quot;&gt;ReportName&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,SUB.&lt;span style=&quot;color: #202020;&quot;&gt;ReportOwner&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,EMail.&lt;span style=&quot;color: #0000FF;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;Value[1]&#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;VARCHAR(1000)&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;as&lt;/span&gt; EMailAddresses&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt;&amp;nbsp; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &amp;nbsp; C.&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;Path&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; ReportPath&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,C.&lt;span style=&quot;color: #202020;&quot;&gt;Name&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; ReportName&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,U.&lt;span style=&quot;color: #202020;&quot;&gt;UserName&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; ReportOwner&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,&lt;span style=&quot;color: #FF00FF;&quot;&gt;CONVERT&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;XML&lt;/span&gt;,SB.&lt;span style=&quot;color: #202020;&quot;&gt;ExtensionSettings&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; Ext&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; ReportServer.&lt;span style=&quot;color: #202020;&quot;&gt;dbo&lt;/span&gt;.&lt;span style=&quot;color: #202020;&quot;&gt;ReportSchedule&lt;/span&gt; RS&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; JOIN ReportServer.&lt;span style=&quot;color: #202020;&quot;&gt;dbo&lt;/span&gt;.&lt;span style=&quot;color: #202020;&quot;&gt;Schedule&lt;/span&gt; S &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;ON&lt;/span&gt; S.&lt;span style=&quot;color: #202020;&quot;&gt;ScheduleID&lt;/span&gt; = RS.&lt;span style=&quot;color: #202020;&quot;&gt;ScheduleID&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AND S.&lt;span style=&quot;color: #202020;&quot;&gt;RecurrenceType&lt;/span&gt; = &lt;span style=&quot;color: #000;&quot;&gt;2&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; OR &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;S.&lt;span style=&quot;color: #202020;&quot;&gt;RecurrenceType&lt;/span&gt; = &lt;span style=&quot;color: #000;&quot;&gt;4&lt;/span&gt; AND &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;S.&lt;span style=&quot;color: #202020;&quot;&gt;DaysOfWeek&lt;/span&gt; &amp;amp;amp; @DaysOfWeek = @DaysOfWeek&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; OR &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;S.&lt;span style=&quot;color: #202020;&quot;&gt;RecurrenceType&lt;/span&gt; = &lt;span style=&quot;color: #000;&quot;&gt;5&lt;/span&gt; AND &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;S.&lt;span style=&quot;color: #202020;&quot;&gt;DaysOfMonth&lt;/span&gt; &amp;amp;amp; @DaysOfMonth = @DaysOfMonth&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; JOIN ReportServer.&lt;span style=&quot;color: #202020;&quot;&gt;dbo&lt;/span&gt;.&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;Catalog&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; C &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;ON&lt;/span&gt; C.&lt;span style=&quot;color: #202020;&quot;&gt;ItemID&lt;/span&gt; = RS.&lt;span style=&quot;color: #202020;&quot;&gt;ReportID&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; JOIN ReportServer.&lt;span style=&quot;color: #202020;&quot;&gt;dbo&lt;/span&gt;.&lt;span style=&quot;color: #202020;&quot;&gt;Subscriptions&lt;/span&gt; SB &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;ON&lt;/span&gt; SB.&lt;span style=&quot;color: #202020;&quot;&gt;SubscriptionID&lt;/span&gt; = RS.&lt;span style=&quot;color: #202020;&quot;&gt;SubscriptionID&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; JOIN ReportServer.&lt;span style=&quot;color: #202020;&quot;&gt;dbo&lt;/span&gt;.&lt;span style=&quot;color: #202020;&quot;&gt;Users&lt;/span&gt; U &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;ON&lt;/span&gt; U.&lt;span style=&quot;color: #202020;&quot;&gt;UserID&lt;/span&gt; = SB.&lt;span style=&quot;color: #202020;&quot;&gt;OwnerID&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; SUB&lt;br /&gt;&amp;nbsp;CROSS APPLY Ext.&lt;span style=&quot;color: #202020;&quot;&gt;nodes&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;/ParameterValues/ParameterValue&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; SubEMail&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;EMail&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;WHERE&lt;/span&gt; &amp;nbsp;EMail.&lt;span style=&quot;color: #0000FF;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;Value[1]&#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;VARCHAR(1000)&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; LIKE &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;%[^ ]@%&#039;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb61490&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/ssrs/getting-ssrs-subscriptions-for-a&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<h2>The Back Story</h2>


<p>This past weekend, work was being done on our exchange server, so e-mail was down most of Saturday.  What everyone (myself included) failed to realize was that this was going to impact scheduled reports from SSRS.</p>

<p>So Monday morning, I got an e-mail asking about which reports should have ran on the Saturday and who they would have gone to.</p>

<p>It sounds like such a simple request that I figured it couldn't be that hard to figure it out.  I was dead wrong.  </p>


<h2>The Hurdles</h2>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/kconan/hurdles.jpg?mtime=1353450411"><img alt="" src="http://blogs.lessthandot.com/media/users/kconan/hurdles.jpg?mtime=1353450411" width="400" height="338" /></a></div>

<p>After poking around in SSRS Web Interface, I quickly found that short of opening each and every subscription there was no way to find this information. Next I took a peek in the ReportServer database where SSRS is hosted and it looked pretty simple.  I peeked in a few tables and the column names all lined up nice for joining to the other tables.  But then I saw the first of two hurdles that wouldn't be so easy to get past.</p>


<h2>Subscriptions.ExtensionSettings</h2>


<p>I found the e-mail addresses that each Subscription is e-mailed to.  The problem (or opportunity) is that it is buried in an XML field - Subscriptions.ExtensionSettings.  This is the first opportunity that I've really had to mess with XML in SQL in a long time so I figured it wouldn't be too bad and I could figure out how to pluck what I needed.</p>

<p>However, my heart sank when I hit the second hurdle.  </p>


<h2>Schedule.RecurrenceType, Schedule.DaysOfWeek and Schedule.DaysOfMonth</h2>


<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/kconan/SSRS_Schedule.JPG?mtime=1353450271"><img alt="" src="http://blogs.lessthandot.com/media/users/kconan/SSRS_Schedule.JPG?mtime=1353450271" width="505" height="136" /></a></div>

<p>The Schedule table has a series of fields where it stores the schedule - Schedule.RecurrenceType, Schedule.DaysOfWeek and Schedule.DaysOfMonth.  This one wasn't going to be as straight forward to get past.  I remember something in the back of my mind about taking a number have to square it or something or another but it was all really fuzzy.</p>


<h2>This can't be the first time someone has had to solve this issue, who's got a blog or forum post about it?!?!</h2>


<p>At this point, I figured it was time to turn to the web.  This has to be an issue that others have come across, so how did they solve it?  After searching around for a while, I wasn't able to find anyone who broke down the schedule fields.  In fact, the only responses from Microsoft on their forums was that they don't support querying them!  It was time for some bigger guns so I turned to twitter and posted on #SQLHELP and #SSRSHELP.  </p>

<p>After a little while and a couple of conversations, people gave me the idea of linking the Schedules to their jobs and pulling the schedules that way.  Linking the Schedules to their Jobs was easy.  However, the job schedules are also difficult to figure out because they are done in a similar way.</p>


<h2>Ah, there's light at the end of this tunnel!</h2>


<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/kconan/tunnel.jpg?mtime=1353450579"><img alt="" src="http://blogs.lessthandot.com/media/users/kconan/tunnel.jpg?mtime=1353450579" width="300" height="224" /></a></div>

<p>The difference between job schedules and subscription schedules is that there ARE posts out there on how to decipher them!  Between the little I was able to find about the schedules and the information about the job schedules, now I had what I needed to decipher the Subscription Schedules.</p>

<p>Remember, I needed to know what report subscriptions should have ran on a specific day.</p>

<p>Schedule.RecurrenceType had 3 values that I needed:</p>

<p>2 - The subscription runs multiple times during the day, every day.  So I want all subscriptions that have that setting.<br />
4 - The subscription runs one or more days a week.  This is used in conjunction with Schedule.DaysOfWeek.<br />
5 - The subscription runs on specific days of the month.  This is used in conjunction with Schedule.DaysOfMonth.</p>

<p>I'm not going to explain bit wise, but here is a link to a BOL Article:</p>

<p><a href="http://msdn.microsoft.com/en-us/library/ms174965.aspx">http://msdn.microsoft.com/en-us/library/ms174965.aspx</a></p>

<p>Schedule.DaysOfWeek and Schedule.DaysOfMonth work off a bit checker (bit wise).  It'll help if you think of the day of the week in terms of what number it is.  For example, Sunday = 1, Monday = 2, Tuesday = 3 etc.</p>

<p>The first value (Sunday and the first of the month) use a bit value of 1.  After that you can figure out the bit value by taking 2 the power of the number you are looking for minus 1.  For example, for the 3rd, it would be 2 to the power of (3 - 1) which is 2 to the power of 2 which equals 4.</p>

<p>So if we were looking for reports that ran on every Tuesday, the TSQL would be Schedule.RecurrenceType = 4 AND Schedule.DaysofWeek &amp; 4 = 4.</p>


<h2>The Query</h2>


<p>I cleaned up the query a little bit by having a variable called @Date that you would set to the date you want to know which subscriptions would have been run on.</p>

<p>The query returns the Path to the Report, the Report Name, the owner of the Subscription and which E-Mail addresses it would have been sent to.</p>

<p>This by no means a finished and completely polished query, but rather a good starting point for others to use for their purposes.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb73497'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb73497','cb47414'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb73497" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">DECLARE</span>&nbsp; @<span style="color: #0000FF;">Date</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DATETIME</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; ,@DaysOfWeek&nbsp; &nbsp; <span style="color: #0000FF;">INT</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; ,@DaysOfMonth&nbsp; &nbsp;<span style="color: #0000FF;">INT</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; </li><li style="" class="li1"><span style="color: #0000FF;">SET</span> @<span style="color: #0000FF;">Date</span>&nbsp; &nbsp;= <span style="color: #FF0000;">'2012-11-17 00:00:00.000'</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> @DaysOfWeek&nbsp; = <span style="color: #0000FF;">CASE</span> <span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span>DW,@<span style="color: #0000FF;">Date</span><span style="color: #808080;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">1</span> &nbsp;<span style="color: #00AF00;">--Sunday</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">2</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">2</span> &nbsp;<span style="color: #00AF00;">--Monday</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">3</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">4</span> &nbsp;<span style="color: #00AF00;">--Tuesday</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">4</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">8</span> &nbsp;<span style="color: #00AF00;">--Wednesday</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">5</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">16</span> <span style="color: #00AF00;">--Thursday</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">6</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">32</span> <span style="color: #00AF00;">--Friday</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">7</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">64</span> <span style="color: #00AF00;">--Saturday</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span>;&nbsp; &nbsp; &nbsp; </li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </li><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> @DaysOfMonth&nbsp;= <span style="color: #0000FF;">CASE</span> <span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span>D,@<span style="color: #0000FF;">Date</span><span style="color: #808080;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">1</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span> <span style="color: #FF00FF;">POWER</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2</span>,<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span>D,@<span style="color: #0000FF;">Date</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">INT</span><span style="color: #808080;">&#41;</span> - <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </li><li style="" class="li2"><span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">DISTINCT</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SUB.<span style="color: #202020;">ReportPath</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; ,SUB.<span style="color: #202020;">ReportName</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; ,SUB.<span style="color: #202020;">ReportOwner</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; ,EMail.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Value[1]'</span>,<span style="color: #FF0000;">'VARCHAR(1000)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">as</span> EMailAddresses&nbsp; &nbsp; &nbsp; </li><li style="" class="li1">&nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; <span style="color: #808080;">&#40;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span> &nbsp; C.<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Path</span><span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> ReportPath</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,C.<span style="color: #202020;">Name</span> <span style="color: #0000FF;">AS</span> ReportName</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,U.<span style="color: #202020;">UserName</span> <span style="color: #0000FF;">AS</span> ReportOwner</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<span style="color: #FF00FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">XML</span>,SB.<span style="color: #202020;">ExtensionSettings</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> Ext</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span> ReportServer.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">ReportSchedule</span> RS</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; JOIN ReportServer.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">Schedule</span> S </li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> S.<span style="color: #202020;">ScheduleID</span> = RS.<span style="color: #202020;">ScheduleID</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp;AND S.<span style="color: #202020;">RecurrenceType</span> = <span style="color: #000;">2</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; OR <span style="color: #808080;">&#40;</span>S.<span style="color: #202020;">RecurrenceType</span> = <span style="color: #000;">4</span> AND <span style="color: #808080;">&#40;</span>S.<span style="color: #202020;">DaysOfWeek</span> &amp;amp; @DaysOfWeek = @DaysOfWeek<span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; OR <span style="color: #808080;">&#40;</span>S.<span style="color: #202020;">RecurrenceType</span> = <span style="color: #000;">5</span> AND <span style="color: #808080;">&#40;</span>S.<span style="color: #202020;">DaysOfMonth</span> &amp;amp; @DaysOfMonth = @DaysOfMonth<span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; JOIN ReportServer.<span style="color: #202020;">dbo</span>.<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Catalog</span><span style="color: #808080;">&#93;</span> C </li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> C.<span style="color: #202020;">ItemID</span> = RS.<span style="color: #202020;">ReportID</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; JOIN ReportServer.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">Subscriptions</span> SB </li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> SB.<span style="color: #202020;">SubscriptionID</span> = RS.<span style="color: #202020;">SubscriptionID</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; JOIN ReportServer.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">Users</span> U </li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> U.<span style="color: #202020;">UserID</span> = SB.<span style="color: #202020;">OwnerID</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> SUB</li><li style="" class="li1">&nbsp;CROSS APPLY Ext.<span style="color: #202020;">nodes</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'/ParameterValues/ParameterValue'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> SubEMail<span style="color: #808080;">&#40;</span>EMail<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">WHERE</span> &nbsp;EMail.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Value[1]'</span>,<span style="color: #FF0000;">'VARCHAR(1000)'</span><span style="color: #808080;">&#41;</span> LIKE <span style="color: #FF0000;">'%[^ ]@%'</span>;</li></ol></div><div id="cb47414" style="display: none; color: red;"></div></div></div><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/ssrs/getting-ssrs-subscriptions-for-a">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/ssrs/getting-ssrs-subscriptions-for-a#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=1901</wfw:commentRss>
		</item>
				<item>
			<title>Setting up a Central Management Server</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/setting-up-a-central-management</link>
			<pubDate>Fri, 29 Jun 2012 11:32:00 +0000</pubDate>			<dc:creator>Kevin Conan</dc:creator>
			<category domain="main">Microsoft SQL Server Admin</category>			<guid isPermaLink="false">1766@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;This is going to be the start of a series on managing multiple SQL Instances.  Up to now, I&#039;ve been mostly writing about Idera&#039;s Diagnostic Manager which is great for this purpose, but like anything else, multiple tools are needed.&lt;/p&gt;

&lt;p&gt;Do you ever find yourself deploying the same code to the same 10 SQL Instances one at a time and wish there was a better way?  Do you keep track of what SQL Instances you have by writing them on Post-It Notes in your cube?  Are your developers always asking you what the names of the SQL Instances are?&lt;/p&gt;

&lt;p&gt;If you answered yes to any of those questions, then you need to setup a Central Management Server! (CMS for short)&lt;/p&gt;

&lt;p&gt;A Central Management Server is basically like a phone book (or a contact list on a phone for you kids too young to remember phone books!).  The other thing CMS allows you to do, is to connect to multiple instances and run a query against all of them from a single SSMS window.&lt;/p&gt;

&lt;p&gt;Setting up a CMS is really easy!  &lt;/p&gt;

&lt;p&gt;First thing to do is pick a SQL Instance that you want to host the CMS (you do not need a dedicated instance for it).  A few things to consider is that the CMS is stored in the msdb, so db_reader (updated thanks to SQLArcher) or ServerGroupReaderRole access is needed for anyone you want to see it.  The amount of disk space needed is very little (less than 100M&lt;img src=&quot;http://blogs.lessthandot.com/rsc/smilies/icon_cool.gif&quot; title=&quot;B)&quot; alt=&quot;B)&quot; class=&quot;middle&quot; width=&quot;15&quot; height=&quot;15&quot; /&gt;.  To plan ahead, choose an instance where the service account that runs the job agent can be given access to all the instances you will list in the CMS (for policy management).  Next, click open SSMS and connect to the chosen instance.&lt;/p&gt;

&lt;p&gt;From the View Menu, choose Registered Servers.  Expand the Database Engine and then right click on Central Management Servers and choose the only option you get which is &quot;Register Central Management Server...&quot;.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/kconan/CMS1.jpg?mtime=1340976654&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/CMS1.jpg?mtime=1340976654&quot; width=&quot;656&quot; height=&quot;526&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;In the Server name, enter the SQL Instance you chose to host the CMS, set Authentication to whatever you shop uses (we use Windows Authentication), in Registered server name you can put in a nickname for the CMS and then you can fill out the description if you want.&lt;/p&gt;

&lt;p&gt;Now if you right click on your CMS, you choose New Server Group to create folders to organize your instances.  To add instances, you would choose New Server Registration and fill it out like you did when you added the CMS.&lt;/p&gt;

&lt;p&gt;Here is a sample of how you could make it look:&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/kconan/CMS2.jpg?mtime=1340976654&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/kconan/CMS2.jpg?mtime=1340976654&quot; width=&quot;265&quot; height=&quot;155&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;If you right click on a folder you can choose New Query which will open a new window that is connected to all the instances in that folder including the children folders).&lt;/p&gt;

&lt;p&gt;If you want to give Developers access to this feature, you will need to set them up with db_datareader (updated thanks to SQLArcher) or ServerGroupReaderRole access to the msdb database.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/setting-up-a-central-management&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>This is going to be the start of a series on managing multiple SQL Instances.  Up to now, I've been mostly writing about Idera's Diagnostic Manager which is great for this purpose, but like anything else, multiple tools are needed.</p>

<p>Do you ever find yourself deploying the same code to the same 10 SQL Instances one at a time and wish there was a better way?  Do you keep track of what SQL Instances you have by writing them on Post-It Notes in your cube?  Are your developers always asking you what the names of the SQL Instances are?</p>

<p>If you answered yes to any of those questions, then you need to setup a Central Management Server! (CMS for short)</p>

<p>A Central Management Server is basically like a phone book (or a contact list on a phone for you kids too young to remember phone books!).  The other thing CMS allows you to do, is to connect to multiple instances and run a query against all of them from a single SSMS window.</p>

<p>Setting up a CMS is really easy!  </p>

<p>First thing to do is pick a SQL Instance that you want to host the CMS (you do not need a dedicated instance for it).  A few things to consider is that the CMS is stored in the msdb, so db_reader (updated thanks to SQLArcher) or ServerGroupReaderRole access is needed for anyone you want to see it.  The amount of disk space needed is very little (less than 100M<img src="http://blogs.lessthandot.com/rsc/smilies/icon_cool.gif" title="B)" alt="B)" class="middle" width="15" height="15" />.  To plan ahead, choose an instance where the service account that runs the job agent can be given access to all the instances you will list in the CMS (for policy management).  Next, click open SSMS and connect to the chosen instance.</p>

<p>From the View Menu, choose Registered Servers.  Expand the Database Engine and then right click on Central Management Servers and choose the only option you get which is "Register Central Management Server...".</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/kconan/CMS1.jpg?mtime=1340976654"><img alt="" src="http://blogs.lessthandot.com/media/users/kconan/CMS1.jpg?mtime=1340976654" width="656" height="526" /></a></div>

<p>In the Server name, enter the SQL Instance you chose to host the CMS, set Authentication to whatever you shop uses (we use Windows Authentication), in Registered server name you can put in a nickname for the CMS and then you can fill out the description if you want.</p>

<p>Now if you right click on your CMS, you choose New Server Group to create folders to organize your instances.  To add instances, you would choose New Server Registration and fill it out like you did when you added the CMS.</p>

<p>Here is a sample of how you could make it look:</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/kconan/CMS2.jpg?mtime=1340976654"><img alt="" src="http://blogs.lessthandot.com/media/users/kconan/CMS2.jpg?mtime=1340976654" width="265" height="155" /></a></div>

<p>If you right click on a folder you can choose New Query which will open a new window that is connected to all the instances in that folder including the children folders).</p>

<p>If you want to give Developers access to this feature, you will need to set them up with db_datareader (updated thanks to SQLArcher) or ServerGroupReaderRole access to the msdb database.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/setting-up-a-central-management">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/setting-up-a-central-management#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=1766</wfw:commentRss>
		</item>
				<item>
			<title>Diagnostic Manager - Alert Statuses</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/diagnostic-manager-alert-statuses</link>
			<pubDate>Thu, 14 Jun 2012 13:22:00 +0000</pubDate>			<dc:creator>Kevin Conan</dc:creator>
			<category domain="alt">Database Administration</category>
<category domain="main">Microsoft SQL Server Admin</category>			<guid isPermaLink="false">1757@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;As you might imagine, I rely on Idera&#039;s Diagnostic Manager quite a bit.  Diagnostic Manager monitors many different things within each SQL Instance will alert to them when they met the thresholds you configure.  Now if you only a few SQL Instances monitored, you may not have many alerts, but if you have dozens of SQL Instances monitored, you could have several dozen alerts all the time.  &lt;/p&gt;

&lt;p&gt;Maybe some of those alerts are not going to cause your system to crash right away, but you want to keep them in mind to show your boss that you need more memory or disk space.&lt;/p&gt;

&lt;p&gt;So how do you know if something critical just happened that you really should look at and isn&#039;t part of the other 50 alerts that just noise for right now?&lt;/p&gt;

&lt;p&gt;This is where I use the different alert statuses and have defined what each status means.&lt;/p&gt;

&lt;p&gt;Critical (Red) status means I want our support center who is watching the alerts page 24x7 to call me anytime of the day or night about it.  I keep things like job failures, disk space that is really low and custom alerts about backups being really behind for example in this spot.  When a alert goes to critical and it is not something that I need to know about immediately, I will re-adjust to only go as far as a warning level.&lt;/p&gt;

&lt;p&gt;Warning (Yellow) status means that this is something that I want to know about and could be become a serious issue, but I don&#039;t need a 3AM wake up call about it.  For me it&#039;s almost as important as a critical alert and is something that I will look at, but I won&#039;t drop everything right now for it.&lt;/p&gt;

&lt;p&gt;OK (Blue) status means it&#039;s something I need to be aware of, but could go for days or weeks before I do something about it.  For example, our dev system is using 90% of the available memory.  That&#039;s fine because it won&#039;t be growing larger than that and we are actually migrating SQL Instances over to a new 2012 Environment.&lt;/p&gt;

&lt;p&gt;This allows me to quickly sort through the alerts to see which ones I should be working on and concerned about (aka, prioritizing my time!)&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/diagnostic-manager-alert-statuses&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>As you might imagine, I rely on Idera's Diagnostic Manager quite a bit.  Diagnostic Manager monitors many different things within each SQL Instance will alert to them when they met the thresholds you configure.  Now if you only a few SQL Instances monitored, you may not have many alerts, but if you have dozens of SQL Instances monitored, you could have several dozen alerts all the time.  </p>

<p>Maybe some of those alerts are not going to cause your system to crash right away, but you want to keep them in mind to show your boss that you need more memory or disk space.</p>

<p>So how do you know if something critical just happened that you really should look at and isn't part of the other 50 alerts that just noise for right now?</p>

<p>This is where I use the different alert statuses and have defined what each status means.</p>

<p>Critical (Red) status means I want our support center who is watching the alerts page 24x7 to call me anytime of the day or night about it.  I keep things like job failures, disk space that is really low and custom alerts about backups being really behind for example in this spot.  When a alert goes to critical and it is not something that I need to know about immediately, I will re-adjust to only go as far as a warning level.</p>

<p>Warning (Yellow) status means that this is something that I want to know about and could be become a serious issue, but I don't need a 3AM wake up call about it.  For me it's almost as important as a critical alert and is something that I will look at, but I won't drop everything right now for it.</p>

<p>OK (Blue) status means it's something I need to be aware of, but could go for days or weeks before I do something about it.  For example, our dev system is using 90% of the available memory.  That's fine because it won't be growing larger than that and we are actually migrating SQL Instances over to a new 2012 Environment.</p>

<p>This allows me to quickly sort through the alerts to see which ones I should be working on and concerned about (aka, prioritizing my time!)</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/diagnostic-manager-alert-statuses">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/diagnostic-manager-alert-statuses#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=1757</wfw:commentRss>
		</item>
			</channel>
</rss>
