Formatting Dates in T-SQL Using CONVERT with Style Codes

CodeProject Assume you've been asked to return a date stored as a datetime2 in a specific format using Transact-SQL. For SQL Server 2012+, one option is to use T-SQL's FORMAT() function. FORMAT() is used with either a .NET format string or a custom formatting string to determine the formatting that should be applied. Starting with … Continue reading Formatting Dates in T-SQL Using CONVERT with Style Codes

SQL Server 2016: Look up the Current UTC Offset and Daylight Savings Time indicator for any Time Zone

Sql Server 2016, ships with a new system catalog view that returns the current UTC Offset for a given time zone and whether the time zone is currently observing Daylight Savings Time. Fun fact: Not all UTC offsets are in one hour increments. Some are only 30 minutes. The time zones listed are the ones … Continue reading SQL Server 2016: Look up the Current UTC Offset and Daylight Savings Time indicator for any Time Zone

Obtain an Exclusive Lock to Rename a SQL Server Database

Tested on: SQL Server 2016 Developer Edition Accurate as of: January, 2018Use this script to rename a database when the SQL Server database could not be exclusively locked to perform the operation. [code language="sql"] -- First, set the database to single user mode ALTER DATABASE CodeSnippets SET SINGLE_USER WITH ROLLBACK IMMEDIATE -- Now we will … Continue reading Obtain an Exclusive Lock to Rename a SQL Server Database

SQL Server Admin: Identifying Active Transactions

Tested on: SQL Server 2016 Developer Edition Accurate as of: January, 2018One way to identify active tractions, is using DBCC OPENTRAN. DBCC OPENTRAN helps to identify active transactions that may be preventing log truncation. DBCC OPENTRAN displays information about the oldest active transaction and the oldest distributed and nondistributed replicated transactions, if any, within the … Continue reading SQL Server Admin: Identifying Active Transactions