<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>2021 on Andy M Mallon - AM²</title><link>https://am2.co/2021/</link><description>Recent content in 2021 on Andy M Mallon - AM²</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Fri, 17 Dec 2021 11:11:50 -0500</lastBuildDate><atom:link href="https://am2.co/2021/index.xml" rel="self" type="application/rss+xml"/><item><title>Querying SERVERPROPERTY() and DATABASEPROPERTYEX() from a view (without knowing magic)</title><link>https://am2.co/2021/12/querying-serverproperty-and-databasepropertyex-from-a-view/</link><pubDate>Fri, 17 Dec 2021 11:11:50 -0500</pubDate><guid>https://am2.co/2021/12/querying-serverproperty-and-databasepropertyex-from-a-view/</guid><description>&lt;p&gt;I&amp;rsquo;m not going to beat around the bush. I hate the &lt;code&gt;SERVERPROPERTY()&lt;/code&gt; and &lt;code&gt;DATABASEPROPERTYEX()&lt;/code&gt; system functions.&lt;/p&gt;&#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>Which install kit installs sqlcmd.exe?</title><link>https://am2.co/2021/12/which-install-kit-installs-sqlcmd-exe/</link><pubDate>Sun, 12 Dec 2021 19:58:18 -0500</pubDate><guid>https://am2.co/2021/12/which-install-kit-installs-sqlcmd-exe/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/303854/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 recently had to uninstall Visual Studio 2012 and DTS, then install VS 2017 and DTS again. Afterwards, The directory containing &lt;code&gt;sqlcmd.exe&lt;/code&gt; was not in my &lt;code&gt;PATH&lt;/code&gt; variable. I installed 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="n"&gt;vs_Professional&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;vs2017&lt;/span&gt;&lt;span class="o"&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;9&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;41&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exe&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="n"&gt;SSDT&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Setup&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;ENU&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;vs2017&lt;/span&gt;&lt;span class="o"&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;9&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exe&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Should either of these kits install &lt;code&gt;sqlcmd.exe&lt;/code&gt;? If not, which tool will install it? I need one that will work with SQL Server 2012+.&lt;/p&gt;</description></item><item><title>log_reuse_wait_desc = AVAILABILITY_REPLICA, log is 100% full but AG is all fine</title><link>https://am2.co/2021/11/log_reuse_wait_desc-availability_replica-log-is-100-full-but-ag-is-all-fine/</link><pubDate>Sun, 28 Nov 2021 18:58:02 -0500</pubDate><guid>https://am2.co/2021/11/log_reuse_wait_desc-availability_replica-log-is-100-full-but-ag-is-all-fine/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/302301/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;That's a weird scenario. The transaction log is full. It waits on AG. AG is all good. No latency, last commit/hardened time is almost real-time on all the nodes. The Estimated Recovery Time is zero. I checked this from the primary node and secondaries as well (in case if Dashboard is not updating).&#10;This &lt;a href="https://learn.microsoft.com/en-us/troubleshoot/sql/availability-groups/error-9002-transaction-log-large" rel="nofollow noreferrer"&gt;page&lt;/a&gt; lists only two reasons for this error, a delivery latency and redo latency. Nothing applies to my system. How to troubleshoot this further?&lt;/p&gt;</description></item><item><title>Order by one column if not null, otherwise by another column, columns are of not matching types</title><link>https://am2.co/2021/11/order-by-one-column-if-not-null-otherwise-by-another-column-columns-are-of-not-matching-types/</link><pubDate>Sun, 28 Nov 2021 18:14:16 -0500</pubDate><guid>https://am2.co/2021/11/order-by-one-column-if-not-null-otherwise-by-another-column-columns-are-of-not-matching-types/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/303220/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 an application that uses PostgreSQL as RDBMS. There is a table containing orders placed by customers. The table has an &lt;code&gt;id&lt;/code&gt; as primary key, an &lt;code&gt;order_number&lt;/code&gt; (integer) and a &lt;code&gt;created_at&lt;/code&gt; field (timestamp). &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;created_at&lt;/code&gt; are assigned automatically when the row is created, the &lt;code&gt;order_number&lt;/code&gt; is assigned &amp;quot;manually&amp;quot; (when the person performing the order entry process receives the order confirmation, he presses a button and the order_number is assigned as &lt;code&gt;MAX(order_number) + 1&lt;/code&gt;, this can happen almost immediately or after a few days, or the order can be cancelled so it never receives a number). In the table there are quite a lot of rows with &lt;code&gt;NULL&lt;/code&gt; in the &lt;code&gt;order_number&lt;/code&gt; column: the cancelled and pending confirmation orders. This is an excerpt from the table:&lt;/p&gt;</description></item><item><title>Database context for sys.databases and sys.master_files</title><link>https://am2.co/2021/11/database-context-for-sys-databases-and-sys-master_files/</link><pubDate>Mon, 15 Nov 2021 11:45:13 -0500</pubDate><guid>https://am2.co/2021/11/database-context-for-sys-databases-and-sys-master_files/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/302628/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 pulls information for a database from the following tables&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;sys.master_files&lt;/li&gt;&#10;&lt;li&gt;sys.databases&lt;/li&gt;&#10;&lt;li&gt;sys.filegroups&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt;Currently, the context set is the specific database which I want to query about.&#10;But if the database is in a mode such that &lt;code&gt;USE DB_NAME&lt;/code&gt; doesn't work,&#10;is it okay to use &lt;code&gt;USE master&lt;/code&gt;?&#10;Since I am adding a &lt;strong&gt;where clause on the basis of &lt;code&gt;DB_NAME&lt;/code&gt;&lt;/strong&gt; will &lt;code&gt;USE DB_NAME&lt;/code&gt; versus &lt;code&gt;USE master&lt;/code&gt; make any difference?&lt;/p&gt;</description></item><item><title>decoding instance_name in sys.dm_os_performance_counters on Azure SQL Database</title><link>https://am2.co/2021/11/decoding-instance_name-in-sys-dm_os_performance_counters-on-azure-sql-database/</link><pubDate>Tue, 09 Nov 2021 19:25:23 -0500</pubDate><guid>https://am2.co/2021/11/decoding-instance_name-in-sys-dm_os_performance_counters-on-azure-sql-database/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/302375/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;doing some work with the SQL Perfmon counters and banging my head against the wall trying to work out how to translate the instance_name column to a database name.&#10;So if I run a query like 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;SELECT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;top&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;left&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counter_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;left&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instance_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;cntr_value&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;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_os_performance_counters&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; &lt;/span&gt;&lt;span class="n"&gt;counter_name&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;Log Bytes Received/sec&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I get a resultset like&lt;/p&gt;</description></item><item><title>SQL Server service - Not Starting With Automatic Startup, "The system cannot find the file specified", but starts fine manually</title><link>https://am2.co/2021/10/sql-server-service-not-starting-with-automatic-startup-the-system-cannot-find-the-file-specified-but-starts-fine-manually/</link><pubDate>Fri, 29 Oct 2021 18:56:27 -0400</pubDate><guid>https://am2.co/2021/10/sql-server-service-not-starting-with-automatic-startup-the-system-cannot-find-the-file-specified-but-starts-fine-manually/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/301898/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 is a weird one, and I've run out of ideas for how to go about troubleshooting this. Here's the issue, best as I can sum it up.&lt;/p&gt;&#10;&lt;p&gt;The SQL Server engine and Agent services are not started when the server first boots when they're set to Automatic. Looked through the Event Viewer, and found these errors:&lt;/p&gt;</description></item><item><title>Are Basic Availability Groups a reliable HA solution without integrity checks on the secondary replica?</title><link>https://am2.co/2021/10/are-basic-availability-groups-a-reliable-ha-solution-without-integrity-checks-on-the-secondary-replica/</link><pubDate>Tue, 26 Oct 2021 16:21:08 -0400</pubDate><guid>https://am2.co/2021/10/are-basic-availability-groups-a-reliable-ha-solution-without-integrity-checks-on-the-secondary-replica/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/301705/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 have a few Basic Availability groups in production and I've been reading about the &lt;a href="https://learn.microsoft.com/en-us/sql/database-engine/availability-groups/windows/basic-availability-groups-always-on-availability-groups?view=sql-server-ver15#limitations" rel="nofollow noreferrer"&gt;limitations&lt;/a&gt; of them. I'm concerned about the following limitations:&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;No backups on secondary replica.&lt;/p&gt;&#10;&lt;p&gt;No integrity checks on secondary replicas.&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;p&gt;Suppose that we haven't failed over in months. In our case, that seems to imply that we haven't run &lt;code&gt;DBCC CHECKDB&lt;/code&gt; for a long time on any of the databases on the secondary. There could have been a storage corruption issue that occurred months ago that we still don't know about. If a disaster occurs on the primary replica and we fail over to the secondary, we might end up with the production application pointing at corrupt data.&lt;/p&gt;</description></item><item><title>Why are there no "Daylight Time" time zones in SQL Server?</title><link>https://am2.co/2021/10/why-are-there-no-daylight-time-time-zones-in-sql-server/</link><pubDate>Thu, 21 Oct 2021 23:11:06 -0400</pubDate><guid>https://am2.co/2021/10/why-are-there-no-daylight-time-time-zones-in-sql-server/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/301484/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 converting the times of some datetimeoffset columns from UTC to Eastern. I am doing this via the command&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;UPDATE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;MyTable&lt;/span&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="n"&gt;MyColumn&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;MyColumn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;TIME&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;ZONE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Eastern Standard Time&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This seemed to be working correctly (times were shifted 4 hours earlier and now have a -04:00 offset, exactly what I wanted), but then I realized that it's not EST, it's EDT right now.&lt;/p&gt;</description></item><item><title>What the heck is the SSISDB? Where does it come from?</title><link>https://am2.co/2021/10/what-the-heck-is-the-ssisdb-where-does-it-come-from/</link><pubDate>Mon, 18 Oct 2021 09:00:15 -0400</pubDate><guid>https://am2.co/2021/10/what-the-heck-is-the-ssisdb-where-does-it-come-from/</guid><description>&lt;p&gt;Back in my day, we stored SQL Server Integration Services (SSIS) packages in msdb, or the file system. Well, I&amp;rsquo;m neither dead nor retired, so that&amp;rsquo;s not an accurate statement&amp;ndash;today is still &amp;ldquo;my time.&amp;rdquo; But when I was learning about SQL Server, those were the only two options. If you or your environment predate SQL Server 2012, then you might only be familiar with those two options.&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/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/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>Is it possible to do a partial transaction log backup with SQL Server 2017? I don't have enough disk space to do a full backup</title><link>https://am2.co/2021/10/is-it-possible-to-do-a-partial-transaction-log-backup-with-sql-server-2017-i-dont-have-enough-disk-space-to-do-a-full-backup/</link><pubDate>Fri, 15 Oct 2021 18:12:37 -0400</pubDate><guid>https://am2.co/2021/10/is-it-possible-to-do-a-partial-transaction-log-backup-with-sql-server-2017-i-dont-have-enough-disk-space-to-do-a-full-backup/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/301199/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;Inherited a database server to maintain and found that the transaction log is 92 GB. My plan is to do the backup of that and get it brought back down to a regular size, then fix it. The problem is I don't have enough disk space on the machine to do the backup locally, then offload. Is there a way I can run the backup for a specified size or time period so I can do it in stages?&lt;/p&gt;</description></item><item><title>Can I use both Log Shipping and Transaction Replication at the same time?</title><link>https://am2.co/2021/10/can-i-use-both-log-shipping-and-transaction-replication-at-the-same-time/</link><pubDate>Fri, 15 Oct 2021 11:36:11 -0400</pubDate><guid>https://am2.co/2021/10/can-i-use-both-log-shipping-and-transaction-replication-at-the-same-time/</guid><description>&lt;p&gt;&lt;a href="https://serverfault.com/q/1080640/299354"&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;Good Morning, I have a SQL Server 2016 that is doing Log Shipping to a DR Site. I currently want to also to Replicate (Transactional) specific Tables to another Server for Reporting Purposes.&lt;/p&gt;&#10;&lt;p&gt;Will there be any issues or snafu&amp;rsquo;s I should be aware of? Can I have Log Shipping and Transactional Replication configured on the same Publishing Database?&lt;/p&gt;</description></item><item><title>T-SQL Tuesday #143: My favorite short scripts</title><link>https://am2.co/2021/10/t-sql-tuesday-143-my-favorite-short-scripts/</link><pubDate>Tue, 12 Oct 2021 10:00:22 -0400</pubDate><guid>https://am2.co/2021/10/t-sql-tuesday-143-my-favorite-short-scripts/</guid><description>&lt;blockquote&gt;For &lt;a href="https://johnmccormack.it/2021/10/t-sql-tuesday-143-short-code-examples/"&gt;this month's T-SQL Tuesday&lt;/a&gt;, John McCormack (&lt;a href="https://johnmccormack.it/" rel="noopener" target="_blank"&gt;blog&lt;/a&gt;) asks us: “What are your go-to short, handy scripts”? I've got so many handy dandy scripts, it was hard to choose.&lt;/blockquote&gt;&#10;&lt;h2 id="where-to-start"&gt;Where to start?&lt;/h2&gt;&#10;&lt;p&gt;I have so many go-to scripts that are short, amazing, and I use all the time. I&amp;rsquo;ve been using SQL Server since the turn of the century, and over the last two decades, I&amp;rsquo;ve found and written a lot of helpful things. And I have a terrible memory, so even if it&amp;rsquo;s just a few lines, I often keep it bookmarked or saved for when I need it. As an aside&amp;ndash;remember that having a folder of utility scripts isn&amp;rsquo;t a sign of weakness or incompetence. If anything, it&amp;rsquo;s the opposite&amp;ndash;those utility scripts are basically all battle scars for the database battles you&amp;rsquo;ve fought over your career. As we become senior, we just fine-tune our collection. With seniority, you don&amp;rsquo;t stop having that collection of scripts&amp;ndash;you just get better at curating them, at making them generic &amp;amp; reusable.&lt;/p&gt;</description></item><item><title>What time is it in Oz?</title><link>https://am2.co/2021/10/what-time-is-it-in-oz/</link><pubDate>Tue, 05 Oct 2021 15:54:03 -0400</pubDate><guid>https://am2.co/2021/10/what-time-is-it-in-oz/</guid><description>&lt;p&gt;There was a &lt;a href="https://dba.stackexchange.com/q/300618/52344" rel="noopener" target="_blank"&gt;recent post on Database Administrators&lt;/a&gt;, where there was some confusion over Daylight Saving Time(DST) in Australian timezones. Let&amp;rsquo;s be honest though&amp;ndash;timezones are confusing, especially when DST comes into play. Arizona Time doesn&amp;rsquo;t observe Daylight Saving Time, so sometimes it&amp;rsquo;s the same as Mountain Time, and sometimes it&amp;rsquo;s Pacific Time.&lt;/p&gt;</description></item><item><title>Database Sizes error; Arithmetic overflow error converting expression to data type int</title><link>https://am2.co/2021/10/database-sizes-error-arithmetic-overflow-error-converting-expression-to-data-type-int/</link><pubDate>Fri, 01 Oct 2021 12:53:23 -0400</pubDate><guid>https://am2.co/2021/10/database-sizes-error-arithmetic-overflow-error-converting-expression-to-data-type-int/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/300451/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 using the below query to pull back database sizes for our SQL instances.&lt;/p&gt;&#10;&lt;p&gt;This cannot pull data larger than 2TB back because of the maximum number the int data type can pull back. How do I go about altering the query to return the database size, no matter how large the dbs?&lt;/p&gt;</description></item><item><title>SQL Server replication additional subscriber</title><link>https://am2.co/2021/09/sql-server-replication-additional-subscriber/</link><pubDate>Wed, 15 Sep 2021 08:48:16 -0400</pubDate><guid>https://am2.co/2021/09/sql-server-replication-additional-subscriber/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/299611/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 publisher with the distributor on the same server which is transactional replication.&#10;There is also an active subscriber using push method.&lt;/p&gt;&#10;&lt;p&gt;I need to set a new subscriber up going to a different server using the same articles as the current subscriber I have. The database is huge and cannot be taken offline so I was going to do an initialize from backup instead of a new snapshot.&lt;/p&gt;</description></item><item><title>Always backup database with encryption</title><link>https://am2.co/2021/09/always-backup-database-with-encryption/</link><pubDate>Sun, 12 Sep 2021 12:36:06 -0400</pubDate><guid>https://am2.co/2021/09/always-backup-database-with-encryption/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/299456/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 force all database and log backups run on the server to be encrypted?&lt;/p&gt;&#10;&lt;p&gt;If encryption is not specified, the query will be terminated.&lt;/p&gt;&#10;&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/299456/52344" rel="noopener" target="_blank"&gt;2021-09-12&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/176952" rel="noopener" target="_blank"&gt;Avi&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&#10;&lt;hr&gt;&#10;&lt;h2 id="answer"&gt;Answer&lt;/h2&gt;&#10;&lt;h2 id="not-in-sql-server"&gt;Not in SQL Server&lt;/h2&gt;&#10;&lt;p&gt;There is no option to force &lt;code&gt;BACKUP DATABASE&lt;/code&gt; &amp;amp; &lt;code&gt;BACKUP LOG&lt;/code&gt; to specify &lt;code&gt;WITH ENCRYPTION...&lt;/code&gt; as part of backup commands in SQL Server.&lt;/p&gt;</description></item><item><title>Partitioning and existing Indexes</title><link>https://am2.co/2021/09/partitioning-and-existing-indexes/</link><pubDate>Sun, 12 Sep 2021 11:11:25 -0400</pubDate><guid>https://am2.co/2021/09/partitioning-and-existing-indexes/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/299454/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 table that consumes almost 1.2 TB of space and has lots of historical data which are mostly irrelevant. Since performing bulk DELETE is going to cause a lot of heavy-lifting, I'm trying to use the concept of horizontal partitioning to create multiple partitions, each containing early data (for eg: 2017,2018... 2021) so that I can simply truncate those partitions which is less than an year, so that I can only retain the relevant operational data.&lt;/p&gt;</description></item><item><title>Identify how many CPUs our database server is using</title><link>https://am2.co/2021/09/identify-how-many-cpus-our-database-server-is-using/</link><pubDate>Thu, 09 Sep 2021 09:48:47 -0400</pubDate><guid>https://am2.co/2021/09/identify-how-many-cpus-our-database-server-is-using/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/300314/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 server where the Microsoft SQL Server 2016 Web Edition server is installed is running very slow.&lt;/p&gt;&#10;&lt;p&gt;We are thinking of increasing the number of cores licensed on it. However, we need to check how many CPU cores the database is using currently. Our Windows Server 2016 has 16 cores (dual) of CPU.&lt;/p&gt;</description></item><item><title>Function to create SQL TABLE does not works well using Powershell</title><link>https://am2.co/2021/09/function-to-create-sql-table-does-not-works-well-using-powershell/</link><pubDate>Thu, 02 Sep 2021 11:41:40 -0400</pubDate><guid>https://am2.co/2021/09/function-to-create-sql-table-does-not-works-well-using-powershell/</guid><description>&lt;p&gt;&lt;a href="https://stackoverflow.com/q/69030492/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 need to get the values from a Excel Sheet (in a shared folder) to export it and then create a SQL Table in my instance. After of this I will execute a Stored Procedure (I already created) in order to create extended properties for a specific schema on tables,columns and rows.&lt;/p&gt;</description></item><item><title>Is it ok to change drive names/labels (NOT Drive Letters!)</title><link>https://am2.co/2021/09/is-it-ok-to-change-drive-names-labels-not-drive-letters/</link><pubDate>Wed, 01 Sep 2021 20:50:32 -0400</pubDate><guid>https://am2.co/2021/09/is-it-ok-to-change-drive-names-labels-not-drive-letters/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/298926/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 realize this is likely a simplistic question but my searches only return results for Drive Letters or Database names if I include SQL Server. Please feel free to point me to existing articles or answers, and my apologies in advance :)&lt;/p&gt;</description></item><item><title>Azure Data Studio - Intellisense does not detect tables, yet queries work</title><link>https://am2.co/2021/08/azure-data-studio-intellisense-does-not-detect-tables-yet-queries-work/</link><pubDate>Mon, 23 Aug 2021 05:08:49 -0400</pubDate><guid>https://am2.co/2021/08/azure-data-studio-intellisense-does-not-detect-tables-yet-queries-work/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/298402/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&amp;rsquo;m breaking some new ground and trying to get into Azure Data Studio. I&amp;rsquo;m having a problem with intellisense that seems to be a bug with Azure Data Studio but I&amp;rsquo;m not sure.&lt;/p&gt;&#10;&lt;p&gt;I have issues with basic queries. Foreign keys, select statements and insert statements are all telling me in this example that chocolate_category does not exist, it says it is an invalid object name, or that the foreign key is invalid because the table name is invalid, etcetera.&lt;/p&gt;</description></item><item><title>insert on table being unnaturally slow</title><link>https://am2.co/2021/08/insert-on-table-being-unnaturally-slow/</link><pubDate>Mon, 16 Aug 2021 16:45:19 -0400</pubDate><guid>https://am2.co/2021/08/insert-on-table-being-unnaturally-slow/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/298118/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 an &amp;quot;Basic&amp;quot; pricing tier Azure SQL database with a table of 7 columns, an ID column of int that is the clustered index and primary key, one datetime2(0) column, 3 varchar(100) columns and 2 varchar(MAX) columns, all nullable.&lt;/p&gt;</description></item><item><title>What are the .BCP files inside a .bacpak file?</title><link>https://am2.co/2021/08/what-are-the-bcp-files-inside-a-bacpak-file/</link><pubDate>Mon, 16 Aug 2021 15:00:01 -0400</pubDate><guid>https://am2.co/2021/08/what-are-the-bcp-files-inside-a-bacpak-file/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/298113/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;Diving on dba.stackexchange.com I found a &lt;a href="https://dba.stackexchange.com/questions/137993/why-is-a-bacpac-file-so-small-compared-to-a-bak-file-of-the-same-database"&gt;nice answer&lt;/a&gt; that teach me how to open a &lt;code&gt;.bacpac&lt;/code&gt; file with File Explorer.&lt;/p&gt;&#10;&lt;p&gt;I gave it a try with the database &lt;code&gt;AdventureWorks2008R2&lt;/code&gt; and all I did was:&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Save the database as &lt;code&gt;.bacpac&lt;/code&gt; file&lt;/li&gt;&#10;&lt;li&gt;Rename the file extension to &lt;code&gt;.zip&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;Unzip it&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt;And there you go, you can see the tables of the database as folders and inside each folder you can see the raw data.&lt;/p&gt;</description></item><item><title>Job to stop other job at specific time</title><link>https://am2.co/2021/08/job-to-stop-other-job-at-specific-time/</link><pubDate>Fri, 13 Aug 2021 11:25:34 -0400</pubDate><guid>https://am2.co/2021/08/job-to-stop-other-job-at-specific-time/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/298011/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 have a job which imports data daily from a remote SQL Server every night, I'll call it Import-Job. Most of the time this job runs through in about 15 minutes and everything is fine but due to a rather unstable VPN connection sometimes the job takes a lot more time.&lt;/p&gt;</description></item><item><title>Getting the first Monday after the third Friday</title><link>https://am2.co/2021/08/getting-the-first-monday-after-the-third-friday/</link><pubDate>Thu, 12 Aug 2021 23:48:40 -0400</pubDate><guid>https://am2.co/2021/08/getting-the-first-monday-after-the-third-friday/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/297986/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 seen on this site how to get the the third Friday of the month:&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; &lt;/span&gt;&lt;span class="n"&gt;quote_date&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;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;table&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;datename&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;weekday&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;quote_date&lt;/span&gt;&lt;span class="p"&gt;)&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;Friday&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;and&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;datepart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;day&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;quote_date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mi"&gt;15&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="n"&gt;datepart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;day&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;quote_date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="mi"&gt;21&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;How would I get the first Monday after this third Friday?&lt;/p&gt;</description></item><item><title>Why putting SQL Agent offline caused WSFC to fail over on passive node?</title><link>https://am2.co/2021/08/why-putting-sql-agent-offline-caused-wsfc-to-fail-over-on-passive-node/</link><pubDate>Thu, 12 Aug 2021 23:17:20 -0400</pubDate><guid>https://am2.co/2021/08/why-putting-sql-agent-offline-caused-wsfc-to-fail-over-on-passive-node/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/297983/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 2 node Windows Failover Cluster with Quorum disk.&#10;SQL agent is NOT a resource of the cluster.&lt;/p&gt;&#10;&lt;p&gt;I needed to enable service broker on the server; for that I need to set SQL Agent offline, run tsql statement then simply put it back online.&lt;/p&gt;</description></item><item><title>Stop using sp_hexadecimal &amp; sp_help_revlogin</title><link>https://am2.co/2021/07/dba-serverlogins/</link><pubDate>Tue, 06 Jul 2021 09:00:52 -0400</pubDate><guid>https://am2.co/2021/07/dba-serverlogins/</guid><description>&lt;p&gt;Since &lt;a class="tweet-ref" href="https://am2.co/2021/07/dba-serverlogins/#tweet-1384126645053771780" data-tweet-id="1384126645053771780"&gt;I started at Stack Overflow&lt;span class="visually-hidden"&gt; (read archived tweet)&lt;/span&gt;&lt;/a&gt;&#10;, I&amp;rsquo;ve had the chance to see some of the interesting challenges with running our databases at our scale.&lt;/p&gt;&#10;&lt;p&gt;My coworker Taryn Pratt (&lt;a href="https://tarynpivots.com/" rel="noopener" target="_blank"&gt;blog&lt;/a&gt;) recently blogged about &lt;a href="https://www.tarynpivots.com/post/2021/fighting-with-deadlocks/" rel="noopener" target="_blank"&gt;fighting with deadlocks&lt;/a&gt; related to &lt;a href="https://stackoverflow.com/teams/" rel="noopener" target="_blank"&gt;Stack Overflow for Teams&lt;/a&gt;.&lt;/p&gt;&#10;&lt;h2 id="lots-of-logins"&gt;Lots of logins&lt;/h2&gt;&#10;&lt;p&gt;Taryn mentions in her post that each team gets their own login, user, schema, etc. This means we have a lot of logins. Additionally, we use Availability Groups for our High Availability, which means we need to keep those logins in sync across AG Replicas.&lt;/p&gt;</description></item><item><title>Identify all tables with an identity column</title><link>https://am2.co/2021/07/identify-all-tables-with-an-identity-column/</link><pubDate>Fri, 02 Jul 2021 18:04:50 -0400</pubDate><guid>https://am2.co/2021/07/identify-all-tables-with-an-identity-column/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/295195/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 query I can run that will show me all tables with an identity column? Trying to figure out if there are any identity based tables whose current identity is nearing upper bound of int32 or int64.&lt;/p&gt;</description></item><item><title>Question Regarding ISDATE Function and DATENAME Functions</title><link>https://am2.co/2021/07/question-regarding-isdate-function-and-datename-functions/</link><pubDate>Thu, 01 Jul 2021 23:50:20 -0400</pubDate><guid>https://am2.co/2021/07/question-regarding-isdate-function-and-datename-functions/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/295143/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 have had an issue this morning with a report failing due to the following error:&lt;/p&gt;&#10;&lt;p&gt;&amp;quot;Conversion failed when converting date and/or time from character string&amp;quot;&lt;/p&gt;&#10;&lt;p&gt;The issue is that in the database we had a value (in a VARCHAR field) of: '31.07/2021'&lt;/p&gt;</description></item><item><title>SQL Server 2012 equivalent of AT TIME ZONE capability</title><link>https://am2.co/2021/06/sql-server-2012-equivalent-of-at-time-zone-capability/</link><pubDate>Wed, 30 Jun 2021 22:11:31 -0400</pubDate><guid>https://am2.co/2021/06/sql-server-2012-equivalent-of-at-time-zone-capability/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/295079/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 in SQL Server 2012 to get what the server time zone would be on a particular date/time? In SQL Server 2016, you have &lt;code&gt;AT TIME ZONE&lt;/code&gt;, but that's not available in 2012. I have a &lt;code&gt;datetimeoffset&lt;/code&gt; and I need to convert it to the server's timezone (on that date) before truncating it to &lt;code&gt;datetime&lt;/code&gt;. &lt;code&gt;SWITCHOFFSET&lt;/code&gt; only works if you know the offset, but for servers that change their timezone twice yearly, the offset will flip back and forth.&lt;/p&gt;</description></item><item><title>Why does SQL Server convert floats to scientific notation?</title><link>https://am2.co/2021/06/why-does-sql-server-convert-floats-to-scientific-notation/</link><pubDate>Mon, 28 Jun 2021 15:28:50 -0400</pubDate><guid>https://am2.co/2021/06/why-does-sql-server-convert-floats-to-scientific-notation/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/294935/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 came across some weird behavior: While passing a float value into a varchar column, the values are getting converted from integers into scientific notation, and it's that scientific notation that gets stored as a string.&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;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;OBJECT_Id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;tempdb..#whydis&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&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; &lt;/span&gt;&lt;span class="k"&gt;begin&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;drop&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="n"&gt;whydis&lt;/span&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;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="n"&gt;OBJECT_Id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;tempdb..#ImSeriously&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&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; &lt;/span&gt;&lt;span class="k"&gt;begin&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;drop&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="n"&gt;ImSeriously&lt;/span&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;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;create&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="n"&gt;whydis&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bigID&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;float&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;create&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="n"&gt;ImSeriously&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bigID&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;255&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;insert&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;into&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="n"&gt;whydis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BigID&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;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1495591&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="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1495289&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="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1495610&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="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1495611&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="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1495609&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="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1495592&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="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1495686&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;INSERT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;INTO&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="n"&gt;ImSeriously&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bigID&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;SELECT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;BigID&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="o"&gt;#&lt;/span&gt;&lt;span class="n"&gt;whydis&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;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; &lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="n"&gt;ImSeriously&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;results look like this:&lt;/p&gt;</description></item><item><title>OLE DB provider "MSOLEDBSQL" with SQL Server not supported?</title><link>https://am2.co/2021/06/ole-db-provider-msoledbsql-with-sql-server-not-supported/</link><pubDate>Mon, 28 Jun 2021 15:28:05 -0400</pubDate><guid>https://am2.co/2021/06/ole-db-provider-msoledbsql-with-sql-server-not-supported/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/279226/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 been using linked server with the old provider (SQLNCLI) without any issue, as recommended &lt;a href="https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-addlinkedserver-transact-sql?view=sql-server-ver15#arguments" rel="noreferrer"&gt;by Microsoft&lt;/a&gt;, I'm planning to switch to new provider (MSOLEDBSQL). I'm able to add linked server using following T-SQL after installing &lt;a href="https://www.microsoft.com/en-us/download/details.aspx?id=56730" rel="noreferrer"&gt;the drivers&lt;/a&gt;&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;EXEC&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sp_addlinkedserver&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="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;SQL02\DEV1&amp;#39;&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="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;srvproduct&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;#39;&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="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;MSOLEDBSQL&amp;#39;&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="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;datasrc&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;SQL02,1933&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Unfortunately, getting following error when I try to query new linked server:&lt;/p&gt;</description></item><item><title>When to partition table in SQL Server based on the amount of memory on server</title><link>https://am2.co/2021/06/when-to-partition-table-in-sql-server-based-on-the-amount-of-memory-on-server/</link><pubDate>Fri, 25 Jun 2021 18:12:44 -0400</pubDate><guid>https://am2.co/2021/06/when-to-partition-table-in-sql-server-based-on-the-amount-of-memory-on-server/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/294826/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 understand that table partitioning is mostly done for data management. I understand that table maintenance becomes more difficult for large tables, since e.g. an index rebuild cannot fit in memory or because e.g. sorts scale with O(n*log(n)) and this causes extra problems with large tables.&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/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/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&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 4145, Level 15, State 1, Procedure usp_BaseScan_CycleCount_Report, Line 16&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;An expression of non-boolean type specified in a context where a condition is expected, near &amp;#39;AND&amp;#39;.&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line hl"&gt;&lt;span class="cl"&gt;Msg 156, Level 15, State 1, Procedure usp_BaseScan_CycleCount_Report, Line 21&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Incorrect syntax near the keyword &amp;#39;ELSE&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/293956/52344" rel="noopener" target="_blank"&gt;2021-06-08&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/232375" rel="noopener" target="_blank"&gt;pdart237&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;</description></item><item><title>SQL Server Configuration - Disabling the "Allow Remote Connections to this Server" Option</title><link>https://am2.co/2021/06/sql-server-configuration-disabling-the-allow-remote-connections-to-this-server-option/</link><pubDate>Mon, 07 Jun 2021 21:16:59 -0400</pubDate><guid>https://am2.co/2021/06/sql-server-configuration-disabling-the-allow-remote-connections-to-this-server-option/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/293896/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 organization had a security audit and was told that we need to DISABLE the &amp;quot;allow remote connection to this server&amp;quot; option for all of our SQL Servers. What impact would this have on connection to the SQL Server via Management Studio (SSMS) from a client machine/desktop or from a web app that might use a connection string or any other external app? All of the documentation I see regarding connectivity issues to a SQL Server seem to include &amp;quot;ENABLING&amp;quot; this option as a solution. Is there a workaround that will allow us to disable it but still allow the access we need from the target clients?&lt;/p&gt;</description></item><item><title>How do I preserve leading zeros for varchar field?</title><link>https://am2.co/2021/05/how-do-i-preserve-leading-zeros-for-varchar-field/</link><pubDate>Mon, 17 May 2021 17:00:31 -0400</pubDate><guid>https://am2.co/2021/05/how-do-i-preserve-leading-zeros-for-varchar-field/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/291730/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 saving a number with leading zeros into a string variable or column, leading zeros are truncated.&lt;/p&gt;&#10;&lt;p&gt;When I run this query:&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;declare&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="nb"&gt;varchar&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;nvarchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&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;set&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="nb"&gt;varchar&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;011&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="n"&gt;print&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The result I get is 11.&lt;/p&gt;&#10;&lt;p&gt;Is there any way to get 011?&lt;/p&gt;</description></item><item><title>How to convert from nchar to decimal in SQL?</title><link>https://am2.co/2021/05/how-to-convert-from-nchar-to-decimal-in-sql/</link><pubDate>Mon, 10 May 2021 18:29:23 -0400</pubDate><guid>https://am2.co/2021/05/how-to-convert-from-nchar-to-decimal-in-sql/</guid><description>&lt;p&gt;&lt;a href="https://stackoverflow.com/q/67475843/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 2 tables(source and destination) which are respectively &lt;code&gt;NOR_LABOR&lt;/code&gt; and &lt;code&gt;ALL_LABOR_DETAILS&lt;/code&gt;. In the source table(&lt;code&gt;NOR_LABOR&lt;/code&gt;) there is a column &lt;code&gt;feet_produced&lt;/code&gt; with the data type &lt;code&gt;nchar(10)&lt;/code&gt;. In the destination table(&lt;code&gt;ALL_LABOR_DETAILS&lt;/code&gt;) there&amp;rsquo;s a column &lt;code&gt;labor_feet_produced&lt;/code&gt; with the data type &lt;code&gt;decimal(18,4)&lt;/code&gt;. I want to convert the &lt;code&gt;feet_produced&lt;/code&gt; from &lt;code&gt;nchar(10)&lt;/code&gt; to &lt;code&gt;decimal(18,4)&lt;/code&gt; and paste it in the &lt;code&gt;ALL_LABOR_DETAILS&lt;/code&gt; table&amp;rsquo;s &lt;code&gt;labor_feet_produced&lt;/code&gt; column.&lt;/p&gt;</description></item><item><title>View SQL Code Behind Flat File Import Wizard?</title><link>https://am2.co/2021/05/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/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>Commit or rollback SQLServer-SQLTransaction when no data changed</title><link>https://am2.co/2021/05/commit-or-rollback-sqlserver-sqltransaction-when-no-data-changed/</link><pubDate>Fri, 07 May 2021 16:11:54 -0400</pubDate><guid>https://am2.co/2021/05/commit-or-rollback-sqlserver-sqltransaction-when-no-data-changed/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/291197/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 use the &lt;a target="_blank" rel="noopener"&gt;SqlTransaction&lt;/a&gt;-class in the backend to access data stored in the MS-SQLServer.&lt;/p&gt;&#10;&lt;p&gt;In some cases we definitely know that no data were changed by this transaction (and no errors occurred).&#10;So the question is: How to close transactions in these cases?&#10;Shall we use &lt;code&gt;Commit()&lt;/code&gt; or &lt;code&gt;Rollback()&lt;/code&gt;, or none of this both functions or something else?&#10;The aim is to find the most performant way to finish the transaction in a &amp;quot;reasonable&amp;quot; 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/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/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>Cardinality , Parallel Hint alternative for MS-SQL</title><link>https://am2.co/2021/03/cardinality-parallel-hint-alternative-for-ms-sql/</link><pubDate>Wed, 31 Mar 2021 10:41:44 -0400</pubDate><guid>https://am2.co/2021/03/cardinality-parallel-hint-alternative-for-ms-sql/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/289017/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;UPDATE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;MARK&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;M&lt;/span&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="n"&gt;ARCHIVE_FLAG&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;N&amp;#39;&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="k"&gt;EXISTS&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="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="cm"&gt;/*+ cardinality(S1, 10) parallel(S1,8)*/&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&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;SHFASG&lt;/span&gt;&lt;span class="w"&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; &lt;/span&gt;&lt;span class="n"&gt;SHIFT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;S1&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; &lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;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;S1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ID&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="n"&gt;M&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;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;S&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MARKID&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="n"&gt;ARCHIVE_FLAG&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Y&amp;#39;&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;This is the oracle query that I have, I want to create similar query for my MS SQL DB, Any help please&lt;/p&gt;</description></item></channel></rss>