<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Querying on Andy M Mallon - AM²</title><link>https://am2.co/tag/querying/</link><description>Recent content in Querying on Andy M Mallon - AM²</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Tue, 08 Nov 2022 03:30:24 -0500</lastBuildDate><atom:link href="https://am2.co/tag/querying/index.xml" rel="self" type="application/rss+xml"/><item><title>Is SQL Server affected by OpenSSL 3.0 Vulnerabilities: CVE 2022-3786 and CVE 2022-3602</title><link>https://am2.co/2022/11/08/is-sql-server-affected-by-openssl-3-0-vulnerabilities-cve-2022-3786-and-cve-2022-3602/</link><pubDate>Tue, 08 Nov 2022 03:30:24 -0500</pubDate><guid>https://am2.co/2022/11/08/is-sql-server-affected-by-openssl-3-0-vulnerabilities-cve-2022-3786-and-cve-2022-3602/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/319330/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I am trying to establish whether SQL Server is affected by the recently discovered OpenSSL vulnerabilities. For example, are SQL Servers that are using TLS/Certificates to encrypt connections between client and server affected to? I believe SQL Server uses Open SSL libraries for encryption purposes. Can someone please shed light on this?&lt;/p&gt;</description></item><item><title>SQL Main query value used in the WHERE in the subquery</title><link>https://am2.co/2022/03/09/sql-main-query-value-used-in-the-where-in-the-subquery/</link><pubDate>Wed, 09 Mar 2022 16:02:11 -0500</pubDate><guid>https://am2.co/2022/03/09/sql-main-query-value-used-in-the-where-in-the-subquery/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/308497/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I'm really confused by this SQL here, I have this sample where I am using the value from the main query in the subquery and then using XML PATH to add a comma between the dates. The setup is 2 tables one with the dates I want to string together. I am not sure why the subquery where statement is not retuning the correct results.&lt;/p&gt;</description></item><item><title>How to await the execution of the rds_backup_database stored procedure?</title><link>https://am2.co/2022/03/03/how-to-await-the-execution-of-the-rds_backup_database-stored-procedure/</link><pubDate>Thu, 03 Mar 2022 13:40:49 -0500</pubDate><guid>https://am2.co/2022/03/03/how-to-await-the-execution-of-the-rds_backup_database-stored-procedure/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/308227/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;Our team is migrating one of our databases to Amazon RDS MS SQL Server. As part of that, we have to rewrite some of our stored procedures.&lt;/p&gt;&#10;&lt;p&gt;We have a stored procedure that performs a database backup to a network storage.&lt;/p&gt;</description></item><item><title>Add default rows to the query result if restrictions are not met</title><link>https://am2.co/2022/02/10/add-default-rows-to-the-query-result-if-restrictions-are-not-met/</link><pubDate>Thu, 10 Feb 2022 13:12:49 -0500</pubDate><guid>https://am2.co/2022/02/10/add-default-rows-to-the-query-result-if-restrictions-are-not-met/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/307298/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I have a SQL query that looks for values in a table on a range of dates.&lt;/p&gt;&#10;&lt;p&gt;If no record is found, I would like to generate rows with default values.&lt;/p&gt;&#10;&lt;p&gt;Example of one of the table existing records:&lt;/p&gt;</description></item><item><title>Querying SERVERPROPERTY() and DATABASEPROPERTYEX() from a view (without knowing magic)</title><link>https://am2.co/2021/12/17/querying-serverproperty-and-databasepropertyex-from-a-view/</link><pubDate>Fri, 17 Dec 2021 11:11:50 -0500</pubDate><guid>https://am2.co/2021/12/17/querying-serverproperty-and-databasepropertyex-from-a-view/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:378px"&gt;&lt;a href="https://www.youtube.com/watch?v=nF4-OOlbvl8" rel="noopener" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/ElphieWitch_Tall-504x1024.jpg" alt="Puppy in a witch costume" width="378" height="768" class="size-large wp-image-10541" /&gt;&lt;/a&gt; Elphaba the pup is growing up!&lt;/figure&gt;&#10;I'm not going to beat around the bush. I hate the `SERVERPROPERTY()` and `DATABASEPROPERTYEX()` system functions. &#10;&lt;h2 id="loathing"&gt;Loathing&lt;/h2&gt;&#10;&lt;p&gt;The thing I hate the most about these two functions is that you need to know the right magic spells to make them work. Let&amp;rsquo;s look at &lt;code&gt;SERVERPROPERTY()&lt;/code&gt; first. The syntax for the function is &lt;code&gt;SERVERPROPERTY( &amp;lsquo;propertyname&amp;rsquo; )&lt;/code&gt;, which is easy enough syntax, but the list of values for &lt;code&gt;propertyname&lt;/code&gt; isn&amp;rsquo;t discoverable from SQL Server metadata, DMVs, or even IntelliSense. Instead, I need to check &lt;a href="https://docs.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-ver15" rel="noopener" target="_blank"&gt;the docs&lt;/a&gt; for the list of allowable values. These property names are essentially magic words, and I need to check my &lt;a href="https://amzn.to/3H6p0Ph" rel="noopener" target="_blank"&gt;spell book&lt;/a&gt; to make sure I get it right.&lt;/p&gt;</description></item><item><title>How do I put the result of stored procedure in a new column in a view?</title><link>https://am2.co/2021/10/17/how-do-i-put-the-result-of-stored-procedure-in-a-new-column-in-a-view/</link><pubDate>Sun, 17 Oct 2021 06:10:18 -0400</pubDate><guid>https://am2.co/2021/10/17/how-do-i-put-the-result-of-stored-procedure-in-a-new-column-in-a-view/</guid><description>&lt;p&gt;&lt;a href="https://stackoverflow.com/q/69601763/1948808"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I have created a stored procedure which takes as inputs a schema name and a table name and outputs an INT containing the largest value in the &lt;code&gt;id&lt;/code&gt; column of the table. I have also created a view containing all the schema names, table names, and primary key column names in my database. I would like to add a column to this view containing the result of my stored procedure, using the schema name and table name values as inputs to the row&amp;rsquo;s stored procedure. I have tried a few different things, but I can&amp;rsquo;t find a way to do it.&lt;/p&gt;</description></item><item><title>An expression of non-boolean type specified in a context where a condition is expected, near 'AND'</title><link>https://am2.co/2021/06/08/an-expression-of-non-boolean-type-specified-in-a-context-where-a-condition-is-expected-near-and/</link><pubDate>Tue, 08 Jun 2021 18:45:31 -0400</pubDate><guid>https://am2.co/2021/06/08/an-expression-of-non-boolean-type-specified-in-a-context-where-a-condition-is-expected-near-and/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/293956/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sql" data-lang="sql"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;PROCEDURE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;dbo&lt;/span&gt;&lt;span class="p"&gt;].[&lt;/span&gt;&lt;span class="n"&gt;usp_BaseScan_CycleCount_Report&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;StartDate&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;EndDate&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;IF&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;StartDate&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AND&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;EndDate&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;IS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;NOT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;dbo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CycleCountHistory&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;RecordDate&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;BETWEEN&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;StartDate&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AND&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;EndDate&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;ELSE&lt;/span&gt;&lt;span class="w"&gt; &#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;dbo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CycleCountHistory&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;blockquote&gt;&#10;&lt;p&gt;Error message: Msg 4145, Level 15, State 1, Procedure&#10;usp_BaseScan_CycleCount_Report, Line 16 An expression of non-boolean&#10;type specified in a context where a condition is expected, near 'AND'.&#10;Msg 156, Level 15, State 1, Procedure usp_BaseScan_CycleCount_Report,&#10;Line 21 Incorrect syntax near the keyword 'ELSE'.&lt;/p&gt;&#10;&lt;/blockquote&gt;</description></item><item><title>View SQL Code Behind Flat File Import Wizard?</title><link>https://am2.co/2021/05/10/view-sql-code-behind-flat-file-import-wizard/</link><pubDate>Mon, 10 May 2021 17:58:41 -0400</pubDate><guid>https://am2.co/2021/05/10/view-sql-code-behind-flat-file-import-wizard/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/291326/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;Is there a way to view and copy the code that the &amp;quot;Import Flat File to SQL&amp;quot; Wizard ultimately uses, after I have gone through all the steps (chosen file, set up data types for my columns, etc.)?&lt;/p&gt;&#10;&lt;p&gt;While using the Import Flat File to SQL wizard, I found it cumbersome to have to select a data type for each column individually. My data had a large amount of columns to change. In the future, I would prefer doing this via SQL code to save time. I'm learning Microsoft SQL Server Studio and currently only know how to use the Import Flat File Wizard, so I would need to learn all the steps for doing it another way.&lt;/p&gt;</description></item><item><title>Why is part of transaction committed when stored procedure faults?</title><link>https://am2.co/2021/04/25/why-is-part-of-transaction-committed-when-stored-procedure-faults/</link><pubDate>Sun, 25 Apr 2021 23:31:33 -0400</pubDate><guid>https://am2.co/2021/04/25/why-is-part-of-transaction-committed-when-stored-procedure-faults/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/290443/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I have a stored procedure that begins by declaring a few variables then contains &lt;code&gt;begin tran;&lt;/code&gt; After this it performs some validations on the supplied arguments (and increments an error count each time a supplied argument fails validation). If there is no error count it then proceeds to carry out 7 inserts. Following this, it has &lt;code&gt;commit tran;&lt;/code&gt;&lt;/p&gt;</description></item><item><title>Job management: How to get the next running date by querying MSDB</title><link>https://am2.co/2020/11/27/job-management-how-to-get-the-next-running-date-by-querying-msdb/</link><pubDate>Fri, 27 Nov 2020 10:10:17 -0500</pubDate><guid>https://am2.co/2020/11/27/job-management-how-to-get-the-next-running-date-by-querying-msdb/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/280429/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;Table &lt;code&gt;sysjobschedules&lt;/code&gt; contains 2 columns &lt;code&gt;next_run_date&lt;/code&gt; and &lt;code&gt;next_run_time&lt;/code&gt;. With the help of &lt;code&gt;sysschedules&lt;/code&gt; and column &lt;code&gt;enable&lt;/code&gt; it should be easy to determine the next running date/time of a specific job.&lt;/p&gt;&#10;&lt;p&gt;However, when you change a schedule, &lt;code&gt;sysjobschedules&lt;/code&gt; is only refreshed 20 minutes after alteration by the Sql Server Agent.&lt;/p&gt;</description></item><item><title>Recursive CTE in SQL Server to count blocking sessions</title><link>https://am2.co/2020/05/18/recursive-cte-in-sql-server-to-count-blocking-sessions/</link><pubDate>Mon, 18 May 2020 19:54:25 -0400</pubDate><guid>https://am2.co/2020/05/18/recursive-cte-in-sql-server-to-count-blocking-sessions/</guid><description>&lt;p&gt;&lt;a href="https://stackoverflow.com/q/72295228/1948808"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I&amp;rsquo;m trying to make CTE to count blocking sessions on server. Currently I made a function to do so(returns blocking session amount). But still could not write this query with CTE.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sql" data-lang="sql"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;FUNCTION&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;dbo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SESSIONS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;SESSION&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;RETURNS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;DECLARE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;returnValue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;SET&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;returnValue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;returnValue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="w"&gt;&#9;&#9;&#9;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#9;&#9;&#9;&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;isNULL&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#9;&#9;&#9;&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;session_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dm_exec_requests&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;R2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;blocking_session_id&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;R1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;blocking_session_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;BLOCKING&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#9;&#9;&#9;&lt;/span&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dm_exec_requests&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;r1&lt;/span&gt;&lt;span class="w"&gt; &#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;blocking_session_id&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;R3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session_id&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#9;&#9;&#9;&lt;/span&gt;&lt;span class="k"&gt;GROUP&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;BY&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;blocking_session_id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#9;&#9;&#9;&lt;/span&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dm_exec_sessions&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;R3&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;where&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;session_id&lt;/span&gt;&lt;span class="o"&gt;=@&lt;/span&gt;&lt;span class="k"&gt;SESSION&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#9;&lt;/span&gt;&lt;span class="k"&gt;DECLARE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;MAX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;session_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dm_exec_requests&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#9;&#9;&#9; &lt;/span&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;blocking_session_id&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;SESSION&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#9;&lt;/span&gt;&lt;span class="k"&gt;IF&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;IS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;NOT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#9;&lt;/span&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#9;&#9;&lt;/span&gt;&lt;span class="k"&gt;SET&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;returnValue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;returnValue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;dbo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SESSIONS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#9;&lt;/span&gt;&lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#9;&lt;/span&gt;&lt;span class="k"&gt;RETURN&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;returnValue&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="qa-attribution qa-attribution-asked"&gt;&lt;span class="qa-attribution-label"&gt;Asked&lt;/span&gt;&lt;span class="qa-attribution-date"&gt;&lt;a href="https://stackoverflow.com/q/72295228/1948808" rel="noopener" target="_blank"&gt;2022-05-18&lt;/a&gt;&lt;/span&gt;&lt;span class="qa-attribution-by"&gt;by&lt;/span&gt;&lt;span class="qa-attribution-user"&gt;&lt;a href="https://stackoverflow.com/users/4715808" rel="noopener" target="_blank"&gt;mortu&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;</description></item><item><title>Making non-SARGable queries seek, without changing the query</title><link>https://am2.co/2020/05/06/making-non-sargable-queries-seek-without-changing-the-query/</link><pubDate>Wed, 06 May 2020 08:36:27 -0400</pubDate><guid>https://am2.co/2020/05/06/making-non-sargable-queries-seek-without-changing-the-query/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=tALDcVmWE9w" rel="noopener noreferrer" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/sarg-pubs-featured-1024x577.png" alt="" width="512" height="289" class="alignright size-large wp-image-3253" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;We&amp;rsquo;ve all been there. You&amp;rsquo;ve got a query where the &lt;code&gt;JOIN&lt;/code&gt; or &lt;code&gt;WHERE&lt;/code&gt; predicate is not &lt;a href="https://dba.stackexchange.com/a/217983/52344" rel="noopener noreferrer" target="_blank"&gt;SARGable&lt;/a&gt;. You&amp;rsquo;ve read about how &lt;a href="https://www.erikdarlingdata.com/2019/04/slightly-less-not-sargable/" rel="noopener noreferrer" target="_blank"&gt;this can be a problem&lt;/a&gt;, and &lt;a href="https://www.erikdarlingdata.com/2019/04/slightly-less-not-sargable/" rel="noopener noreferrer" target="_blank"&gt;how bad it is for performance&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;Alas, you cannot change the query. Sometimes this reason is political, sometimes it&amp;rsquo;s because you&amp;rsquo;ve got a third-party app and simply don&amp;rsquo;t have access to the code. But you do have access to the database&amp;hellip;&lt;/p&gt;</description></item><item><title>Is it possible to re-use a query plan from the plan cache from one database in another database?</title><link>https://am2.co/2019/11/01/is-it-possible-to-re-use-a-query-plan-from-the-plan-cache-from-one-database-in-another-database/</link><pubDate>Fri, 01 Nov 2019 18:08:43 -0400</pubDate><guid>https://am2.co/2019/11/01/is-it-possible-to-re-use-a-query-plan-from-the-plan-cache-from-one-database-in-another-database/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/252394/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;For example, if I hit the sys dynamic views to select a specific query plan, am I able to insert that query plan into another database's plan cache, that runs the same exact query? (I know the query is hashed and compared to determine when to generate a new plan, so in my example I would ensure the query truly is exactly the same character by character.)&lt;/p&gt;</description></item><item><title>How To Fix High DTU Usage on Specific Query</title><link>https://am2.co/2019/10/10/how-to-fix-high-dtu-usage-on-specific-query/</link><pubDate>Thu, 10 Oct 2019 18:03:01 -0400</pubDate><guid>https://am2.co/2019/10/10/how-to-fix-high-dtu-usage-on-specific-query/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/250789/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I have a query that runs every few seconds on a Microsoft SQL Azure Database. It is from a web job that checks if there are actions that need to be done based on rows in a specific table (its a queueing table). Based on the image attached, does anyone have any suggestion of how i could reduce the DTU usage for the query in question, it is causing the database to reach 100% CPU. &lt;/p&gt;</description></item><item><title>Performance Myths: The query result cache</title><link>https://am2.co/2018/07/23/performance-myths-the-query-result-cache/</link><pubDate>Mon, 23 Jul 2018 10:48:11 -0400</pubDate><guid>https://am2.co/2018/07/23/performance-myths-the-query-result-cache/</guid><description>&lt;img src="https://am2.co/wp-content/uploads/Myths-am-qrc-feat.png" alt="" width="850" height="130" class="alignnone size-full wp-image-2911" /&gt;&#10;&lt;p&gt;I was recently doing a training session when a developer commented that it was OK to run an expensive query twice because on the second execution, SQL Server would use the &amp;ldquo;results cache&amp;rdquo; and be &amp;ldquo;practically free&amp;rdquo;. It&amp;rsquo;s not the first time I&amp;rsquo;ve heard someone refer to a &amp;ldquo;results cache&amp;rdquo; in SQL Server. This is one of those myths that is almost true, which makes it that much more believable. If you don&amp;rsquo;t know better, you might think SQL Server has a &amp;ldquo;results cache&amp;rdquo; because the second execution of a query is often faster.&lt;/p&gt;</description></item><item><title>Deadlock when creating a database - A Query Store bug</title><link>https://am2.co/2018/03/20/deadlock-query-store-bug/</link><pubDate>Tue, 20 Mar 2018 09:00:17 -0400</pubDate><guid>https://am2.co/2018/03/20/deadlock-query-store-bug/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=4n5sBh5hozU" rel="noopener" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/QueryStore-300x225.jpg" alt="" width="300" height="225" class="alignright size-medium wp-image-1363" /&gt;&lt;/a&gt;&#10;Earlier tonight, I sat down to install &lt;a href="https://docs.microsoft.com/en-us/sql/reporting-services/create-deploy-and-manage-mobile-and-paginated-reports" rel="noopener" target="_blank"&gt;Reporting Services&lt;/a&gt; on my laptop. I haven&amp;rsquo;t played with SSRS 2017 yet, so I figured I&amp;rsquo;d poke around some. Much to my surprise, the configuration failed when creating the ReportServer database, reporting a deadlock. When I looked at the database instance, I found the ReportServer database there, but with no objects it in, and the ReportServerTempDB database missing.&lt;/p&gt;</description></item><item><title>Interviewed by Mohammad Darab</title><link>https://am2.co/2017/12/20/interviewed-mohammad-darab/</link><pubDate>Wed, 20 Dec 2017 10:01:42 -0500</pubDate><guid>https://am2.co/2017/12/20/interviewed-mohammad-darab/</guid><description>&lt;p&gt;&lt;img class="alignright size-full wp-image-1240" src="https://am2.co/wp-content/uploads/Mohammad-Darab.png" alt="" width="200" height="200" /&gt;As part of Mohammad&amp;rsquo;s series of interviews, he interviewed me on my thoughts on the future of SQL Server, the DBA role, and the cloud.&lt;/p&gt;&#10;&lt;p&gt;Read the interview on &lt;a href="https://mohammaddarab.com/interview-andy-mallon/" target="_blank" rel="noopener"&gt;Mohammad&amp;rsquo;s site&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Query a view in a procedure in which the view name is a variable</title><link>https://am2.co/2017/08/16/query-a-view-in-a-procedure-in-which-the-view-name-is-a-variable/</link><pubDate>Wed, 16 Aug 2017 18:18:49 -0400</pubDate><guid>https://am2.co/2017/08/16/query-a-view-in-a-procedure-in-which-the-view-name-is-a-variable/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/183661/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;My problem: I have a set of views from which I want to query dynamically.&#10;I want to load the view names by &lt;strong&gt;&lt;code&gt;SELECT * from sys.all_views&lt;/code&gt;&lt;/strong&gt; into a cursor (let's call it &lt;code&gt;view_cursor&lt;/code&gt;) and then do something like this in a procedure:&lt;/p&gt;</description></item><item><title>Reconnect "not connected" query windows in SSMS to original connection</title><link>https://am2.co/2017/08/14/reconnect-not-connected-query-windows-in-ssms-to-original-connection/</link><pubDate>Mon, 14 Aug 2017 14:20:38 -0400</pubDate><guid>https://am2.co/2017/08/14/reconnect-not-connected-query-windows-in-ssms-to-original-connection/</guid><description>&lt;!-- REPLACE:&#10;Question ID: 183432&#10;Asker Name: David Hiltenbrand&#10;Asker ID: 132635&#10;Question Date: 2017-08-14&#10;&#10;Answer ID: 183434&#10;Answer Date: 2017-08-14&#10;&#10;--&gt;&#10;&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/183432/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;Is there a simple way to reconnect a query window that is &amp;ldquo;not connected&amp;rdquo; to the original connection that was used by that query without manually picking the server name needed? If I click the Connect button on the SQL Editor toolbar or right click -&amp;gt; Connection -&amp;gt; Connect&amp;hellip; it defaults the server name to the last connection I used in that SSMS session, not to the last connection used by that specific query window.&lt;/p&gt;</description></item><item><title>Why does it take so long to view logs on a server?</title><link>https://am2.co/2017/04/20/why-does-it-take-so-long-to-view-logs-on-a-server/</link><pubDate>Thu, 20 Apr 2017 12:20:14 -0400</pubDate><guid>https://am2.co/2017/04/20/why-does-it-take-so-long-to-view-logs-on-a-server/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/171510/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I am just trying to look up more verbose information for a maintenance plan task that failed. I open up the log file viewer and check the box to view the logs for my maintenance plan. There are no active filters besides that in this example. Then I play the waiting game.....&lt;/p&gt;</description></item><item><title>Keyboard shortcut to close a query tab in SSMS</title><link>https://am2.co/2017/01/27/close-ssms-tab/</link><pubDate>Fri, 27 Jan 2017 08:00:22 -0500</pubDate><guid>https://am2.co/2017/01/27/close-ssms-tab/</guid><description>&lt;h2 id="shortcuts--tips-from-an-impatient-dba"&gt;Shortcuts &amp;amp; tips from an Impatient DBA&lt;/h2&gt;&#10;&lt;p&gt;This series of short posts will demonstrate some lesser-known features, keyboard shortcuts, and other tips that make my day as a DBA more productive. None of these are groundbreaking super-secret features–they are the little things that I do as part of my daily work that make me more efficient.&lt;/p&gt;</description></item><item><title>What's the deal with transactions in a stored procedure called by an SSRS report?</title><link>https://am2.co/2016/03/01/whats-the-deal-with-transactions-in-a-stored-procedure-called-by-an-ssrs-report/</link><pubDate>Tue, 01 Mar 2016 23:00:41 -0500</pubDate><guid>https://am2.co/2016/03/01/whats-the-deal-with-transactions-in-a-stored-procedure-called-by-an-ssrs-report/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/130948/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;Consider the following:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sql" data-lang="sql"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;PROCEDURE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;dbo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;usp_trantest&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@@&lt;/span&gt;&lt;span class="n"&gt;TRANCOUNT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;trancount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;GO&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;When I call &lt;code&gt;usp_trantest&lt;/code&gt; manually from within SSMS, the trancount is 0. If I run an SSRS report that contains a dataset that queries the same stored procedure, the trancount is logged as 1.&lt;/p&gt;</description></item><item><title>SSMS Query Shortcuts</title><link>https://am2.co/2015/05/28/shortcuts-tips-4/</link><pubDate>Thu, 28 May 2015 13:30:00 -0400</pubDate><guid>https://am2.co/2015/05/28/shortcuts-tips-4/</guid><description>&lt;h2 id="shortcuts--tips-from-an-impatient-dba-4"&gt;Shortcuts &amp;amp; tips from an Impatient DBA #4&lt;/h2&gt;&#10;&lt;p&gt;This series of short posts will demonstrate some lesser-known features, keyboard shortcuts, and other tips that make my day as a DBA more productive. None of these are groundbreaking super-secret features&amp;ndash;they are the little things that I do as part of my daily work that make me more efficient.&lt;/p&gt;</description></item></channel></rss>