MS SQL – Normalise Case

Wow not wrote any notes for a very long time…! Recently I’ve had an issue where some text was presented in a table, and I needed to normalise the text. For example: Would need to become: With thanks to Justin Cooney this was possible using the SQL below: The code…

SQL Server – Identify Unused Indexes

Within SQL Server an index is used to optimise the reading of data from the database. However the side effect of having such an index is reduced write speed for inserts and updates. This is because SQL Server will need to update and maintain the index. Running the below SQL…

Azure SQL Database View Running Transactions / Blocking

With the Azure SQL Database, sometimes you want to view the current running transactions. Unfortunately there is no GUI as such like there is with normal SQL Server (right click, “Activity Monitor”), however it can be grabbed by executing sys.dm_exec_requests. The following SQL is very useful as it shows details…

Azure SQL Database Index Size

Recently I’ve been doing some work on optimising indexes within Azure SQL Database. The following SQL from Daniel is very useful in showing the status of all the current indexes within a SQL Database. The SQL works for both SQL Server 2014 onwards, plus Azure SQL Database. I have not…

Delete Duplicate Records – Leave Only 1 Behind MS SQL

Recently I’ve had to delete duplicate records from the Record Link table in Microsoft Dynamics Nav. Using the following SQL, (which uses the OVER clause for partitioning) this deletes all duplicate records, leaving the first unique item behind. The SQL can be updated easily to function for other tables /…

Microsoft Dynamics NAV – View All Active Sessions

With Microsoft Dynamics Nav, there are various ways of viewing all the active sessions within the system. The easiest of which is the “Sessions” page within the software itself: The downside of this, is that it only shows active sessions on the tier which the user is connected. This is…

Convert MS SQL Query to MySQL Automatically

With a recent project, I’ve had to reproduce a table from a Microsoft SQL Database into a MySQL Database. The table had lots of fields and would be very time consuming to write the SQL to create the table, but luckily I came across this tool to convert MSSQL to…

SQL Remove Trailing Decimal Places

Within a recent project, I’ve been extracting data from Microsoft Dynamics NAV using Taskcentre. Within NAV, decimals are stored as decimal(38,20), complete will all 20 decimal places..! The following SQL query is very handy at removing the un-required decimal places (but keeping the accuracy of the data) The results of…

SQL Server – Find Last Backup Date/Time

With SQL server and 3rd party backup software, it can sometimes be difficult to tell when the last SQL backup has been taken and if the backup software has actually performed the backup or not. There are 3 main backup types in SQL Server: Full Incremental Transaction Log The following…