<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>2022 on Andy M Mallon - AM²</title><link>https://am2.co/2022/</link><description>Recent content in 2022 on Andy M Mallon - AM²</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Sat, 24 Dec 2022 18:35:57 -0500</lastBuildDate><atom:link href="https://am2.co/2022/index.xml" rel="self" type="application/rss+xml"/><item><title>Using OPENJSON, can't get results to GROUP BY</title><link>https://am2.co/2022/12/using-openjson-cant-get-results-to-group-by/</link><pubDate>Sat, 24 Dec 2022 18:35:57 -0500</pubDate><guid>https://am2.co/2022/12/using-openjson-cant-get-results-to-group-by/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/306522/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 passing a JSON string to a stored procedure in order to insert warehouse inventory.&lt;/p&gt;&#10;&lt;p&gt;Sometimes, there will be multiple line items with the same product, going to the same shelf, on the same pallet (LPN), with the same date. I would like to aggregate those into one line in the table.&lt;/p&gt;</description></item><item><title>SQL Modulo Function gives the wrong value?</title><link>https://am2.co/2022/11/sql-modulo-function-gives-the-wrong-value/</link><pubDate>Fri, 18 Nov 2022 15:04:29 -0500</pubDate><guid>https://am2.co/2022/11/sql-modulo-function-gives-the-wrong-value/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/319890/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;In Javascript, Excel, Python, and a scientific calculator, the modulo operation&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="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;34086&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1576962834&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="mi"&gt;360&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="c1"&gt;-- python&#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="k"&gt;MOD&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;34086&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1576962834&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;360&lt;/span&gt;&lt;span class="p"&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; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="c1"&gt;-- Excel function&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;gives a value of &lt;code&gt;113.84230371659942&lt;/code&gt;. (Or something very close to that, depending on number of decimal places and rounding.)&lt;/p&gt;</description></item><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/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/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>What's the use case of disabling an index?</title><link>https://am2.co/2022/09/whats-the-use-case-of-disabling-an-index/</link><pubDate>Sun, 25 Sep 2022 17:10:28 -0400</pubDate><guid>https://am2.co/2022/09/whats-the-use-case-of-disabling-an-index/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/317371/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 just learned that indexes can be disabled on a table. Even the clustered index can be disabled. After that, users can&amp;rsquo;t access the index or the data if clustered index. When will we disable an index? I just don&amp;rsquo;t understand the use case.&lt;/p&gt;</description></item><item><title>What ports to open for sql server behind secure domain firewall</title><link>https://am2.co/2022/08/what-ports-to-open-for-sql-server-behind-secure-domain-firewall/</link><pubDate>Thu, 25 Aug 2022 21:34:17 -0400</pubDate><guid>https://am2.co/2022/08/what-ports-to-open-for-sql-server-behind-secure-domain-firewall/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/316082/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;We are trying to solve connectivity issues for one of the app trying to pull data from very secured sql server behind firewall. I am not that expertise in security but need help on how to proceed in opening ports for that app to pull data from sql server behind secure domain.&lt;/p&gt;</description></item><item><title>snapshot replication - corrupted BCP files</title><link>https://am2.co/2022/08/snapshot-replication-corrupted-bcp-files/</link><pubDate>Thu, 18 Aug 2022 22:56:09 -0400</pubDate><guid>https://am2.co/2022/08/snapshot-replication-corrupted-bcp-files/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/315798/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;Each night my SQLServer replication failed on a big table with the following error. It is failing on a different table each night but always on a relatively big table ( &amp;gt; 200,000 rows)&lt;/p&gt;&#10;&lt;p&gt;The process could not bulk copy into table '&amp;quot;dbo&amp;quot;.&amp;quot;Table01&amp;quot;'. (Source: MSSQL_REPL, Error number: MSSQL_REPL20037)&lt;br /&gt;&#10;Get help: http://help/MSSQL_REPL20037&lt;br /&gt;&#10;&lt;strong&gt;Field size too large&lt;br /&gt;&#10;Batch send failed&lt;/strong&gt;&lt;br /&gt;&#10;Violation of PRIMARY KEY constraint 'PK_Table01'. Cannot insert duplicate key in object 'dbo.Table01'. The duplicate key value is (0). (Source: MSSQLServer, Error number: 2627)&lt;br /&gt;&#10;Get help: http://help/2627&lt;br /&gt;&#10;Failed to send batch after max errors (Source: MSSQLServer, Error number: 3621)&lt;br /&gt;&#10;Get help: http://help/3621&lt;/p&gt;</description></item><item><title>Publishing a Code of Conduct isn't enough</title><link>https://am2.co/2022/07/publishing-a-code-of-conduct-isnt-enough/</link><pubDate>Wed, 13 Jul 2022 16:24:03 -0400</pubDate><guid>https://am2.co/2022/07/publishing-a-code-of-conduct-isnt-enough/</guid><description>&lt;p&gt;I&amp;rsquo;ve seen more and more events &amp;amp; communities adopt Codes of Conduct. Even local events, local user groups, and smaller online communities are adopting Codes of Conduct. That&amp;rsquo;s GREAT! &amp;hellip;but it&amp;rsquo;s just a great start. It&amp;rsquo;s not that easy.&lt;/p&gt;&#10;&lt;h2 id="discoverability"&gt;Discoverability&lt;/h2&gt;&#10;&lt;p&gt;The issue of discoverability is common, but easy to fix. Let&amp;rsquo;s look at a specific scenario. An event publishes a Code of Conduct, and has attendees agree to it when they sign up to attend. That&amp;rsquo;s all great. But during the event someone experiences, witnesses, or hears about behavior that sounds like a Code of Conduct violation. They didn&amp;rsquo;t think it would happen to them&amp;ndash;even though they read &amp;amp; agreed to the Code of Conduct, they don&amp;rsquo;t have it memorized and need to go find it. &lt;em&gt;Where do they find it?&lt;/em&gt;&lt;/p&gt;</description></item><item><title>GRANT ADMINISTER Database Bulk Operations - Incorrect syntax near ADMINISTER</title><link>https://am2.co/2022/05/grant-administer-database-bulk-operations-incorrect-syntax-near-administer/</link><pubDate>Mon, 23 May 2022 01:51:34 -0400</pubDate><guid>https://am2.co/2022/05/grant-administer-database-bulk-operations-incorrect-syntax-near-administer/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/312469/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 import a bacpac file to my SQL Server Express 2016.&#10;An exception is thrown during the import with&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;GRANT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ADMINISTER&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;Database&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Bulk&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Operations&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;TO&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;MyUser&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Returns:&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;Incorrect syntax near 'ADMINISTER'.&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;p&gt;I am running the import as the &lt;code&gt;sa&lt;/code&gt; user. Later when I try to run the SQL line directly, the same error is thrown. What can I do to resolve this?&lt;/p&gt;</description></item><item><title>How do I generate the private key needed to restore the encrypted backup?</title><link>https://am2.co/2022/04/how-do-i-generate-the-private-key-needed-to-restore-the-encrypted-backup/</link><pubDate>Fri, 22 Apr 2022 01:10:13 -0400</pubDate><guid>https://am2.co/2022/04/how-do-i-generate-the-private-key-needed-to-restore-the-encrypted-backup/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/311218/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 simulating the situation where I take a backup from instance &lt;strong&gt;A&lt;/strong&gt; and restore it on instance &lt;strong&gt;B&lt;/strong&gt;. I followed the doc to &lt;a href="https://learn.microsoft.com/en-us/sql/relational-databases/backup-restore/create-an-encrypted-backup?view=sql-server-ver15#backup-to-disk-with-encryption" rel="nofollow noreferrer"&gt;Backup to Disk with Encryption&lt;/a&gt;. Since I'm using only my desktop to simulate the whole process, after taking the backup of the database I took a backup of the certificate that was used as follows:&lt;/p&gt;</description></item><item><title>Temporarily turn on Cascade Delete</title><link>https://am2.co/2022/04/temporarily-turn-on-cascade-delete/</link><pubDate>Wed, 20 Apr 2022 10:02:25 -0400</pubDate><guid>https://am2.co/2022/04/temporarily-turn-on-cascade-delete/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/312379/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;This has probably been asked before, but I couldn't find the answer.&lt;/p&gt;&#10;&lt;p&gt;I have a complex datamodel in sql-server-20XX (more likely to be something old) in which cascade delete has been turned off (by design).&lt;/p&gt;&#10;&lt;p&gt;A large chunk of our database has been sold (I can make the distinction on the top-level) and there are reasons why we want to delete that data. I want to do that in a single script, in which I first turn on cascade delete, than delete all the data, than turn off cascade delete again, but I can't find the correct syntax.&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/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/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 do I prevent a trigger from firing for one process?</title><link>https://am2.co/2022/03/how-do-i-prevent-a-trigger-from-firing-for-one-process/</link><pubDate>Tue, 08 Mar 2022 09:00:16 -0500</pubDate><guid>https://am2.co/2022/03/how-do-i-prevent-a-trigger-from-firing-for-one-process/</guid><description>&lt;p&gt;I recently saw a question on DBA Stack Exchange (it has since been deleted by the author), who had a &amp;ldquo;special process&amp;rdquo; that ran regularly, and as part of that process, they disabled the trigger, did some stuff, and re-enabled it. During that process, the step that disables the trigger would deadlock, and cause problems. So the asker was wondering how to catch &amp;amp; handle the deadlock during the &lt;code&gt;DISABLE TRIGGER&lt;/code&gt; step.&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/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/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>How to change the web browser used by SSMS when you hit Ctrl+Alt+R</title><link>https://am2.co/2022/02/how-to-change-the-web-browser-used-by-ssms-when-you-hit-ctrlaltr/</link><pubDate>Tue, 15 Feb 2022 01:32:52 -0500</pubDate><guid>https://am2.co/2022/02/how-to-change-the-web-browser-used-by-ssms-when-you-hit-ctrlaltr/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/307496/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;When I am running:&lt;/p&gt;&#10;&lt;a href="https://am2.co/wp-content/uploads/dba-se-307496-1.png"&gt;&lt;img src="https://am2.co/wp-content/uploads/dba-se-307496-1-298x300.png" alt="Stack Exchange answer screenshot showing the SSMS browser setting." width="298" height="300" class="aligncenter size-medium wp-image-55798" /&gt;&lt;/a&gt;&#10;&lt;p&gt;Ctrl+Alt+R will run the web browser in an SSMS tab. However, this now produces the message:&lt;/p&gt;&#10;&lt;a href="https://am2.co/wp-content/uploads/dba-se-307496-2.png"&gt;&lt;img src="https://am2.co/wp-content/uploads/dba-se-307496-2-300x58.png" alt="SSMS setting showing the configured web browser." width="300" height="58" class="aligncenter size-medium wp-image-55799" /&gt;&lt;/a&gt;&#10;&lt;p&gt;I do have MS Edge installed but SSMS is not finding it. What should I do to help SSMS find MS Edge and use it?&lt;/p&gt;</description></item><item><title>Allow create table (dynamic name) and insert but nothing else</title><link>https://am2.co/2022/02/allow-create-table-dynamic-name-and-insert-but-nothing-else/</link><pubDate>Mon, 14 Feb 2022 13:43:43 -0500</pubDate><guid>https://am2.co/2022/02/allow-create-table-dynamic-name-and-insert-but-nothing-else/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/307467/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 trying to find a way to allow an application to create tables and insert data into them on a SQL Server 2019 while protecting from injection attacks in case the app credentials would leak. My experience is limited when it comes to writing code that can run in parallel and writing dynamic sql that is protected from sql injection attacks.&lt;br /&gt;&#10;The table name is based on input from the application, i.e. if the input is 'nds' the table name should be lake.nds_raw_log.&lt;br /&gt;&#10;It is my understanding that there is no way to do this via directly granting permissions to the role for this application since creating tables is not separated from deleting or altering them.&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/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/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>How to revoke SA permissions that seem to be "stuck" to a login?</title><link>https://am2.co/2022/02/how-to-revoke-sa-permissions-that-seem-to-be-stuck-to-a-login/</link><pubDate>Wed, 02 Feb 2022 13:29:23 -0500</pubDate><guid>https://am2.co/2022/02/how-to-revoke-sa-permissions-that-seem-to-be-stuck-to-a-login/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/307824/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;Apologies in advance if I don't use some terminology correctly here. I'm not a DBA but I've been temporarily forced into the role.&lt;/p&gt;&#10;&lt;p&gt;I've inherited an application that runs on SQL Server 2016 Enterprise - one instance for PROD and another for TEST. These instances are set up in an &amp;quot;always on&amp;quot; configuration, so I have one Availability Group for PROD and one for TEST. Each Availability Group has two servers in it. Each instance has multiple databases in it, but only one DB in each instance is actually used by the application - the others look to have been created for testing purposes. I'm only mentioning that there are other DBs just in case it might be relevant in some way that I'm not aware of.&lt;/p&gt;</description></item><item><title>CASE statement issue</title><link>https://am2.co/2022/01/case-statement-issue/</link><pubDate>Thu, 13 Jan 2022 19:52:17 -0500</pubDate><guid>https://am2.co/2022/01/case-statement-issue/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/306069/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;Can anyone help with this error?&lt;/p&gt;&#10;&lt;p&gt;SQL:&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;SELECT&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="n"&gt;InvoiceDate&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="n"&gt;BillingAddress&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="n"&gt;BillingCity&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="n"&gt;Total&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; &lt;/span&gt;&lt;span class="k"&gt;CASE&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;WHEN&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Total&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;THEN&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Baseline Purchase&amp;#39;&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;WHEN&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Total&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;00&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="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;99&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;THEN&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Low Purchase&amp;#39;&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;WHEN&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Total&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="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;00&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="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;THEN&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Target Purchase&amp;#39;&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;ELSE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Top Performer&amp;#39;&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; &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;PurchaseType&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;FROM&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="n"&gt;invoices&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;WHERE&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="n"&gt;PurchaseType&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="s1"&gt;&amp;#39;Top Performer&amp;#39;&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;ORDER&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; &#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="n"&gt;BillingCity&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="sql-output"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line hl"&gt;&lt;span class="cl"&gt;Msg 207, Level 16, State 1, Line 13&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Invalid column name &amp;#39;PurchaseType&amp;#39;.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&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://dba.stackexchange.com/q/306069/52344" rel="noopener" target="_blank"&gt;2022-01-13&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://dba.stackexchange.com/users/246235" rel="noopener" target="_blank"&gt;Mark_72&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;</description></item></channel></rss>