Categories
SQL

Sharing is Caring: Exchanging Values within Sessions

When developing application code we may be familiar with exchanging data and objects through the application. This practice is much less common in SQL due to being transactional when we consider application / OLTP workloads. There are however some times when exchanging values between code in the same session which is what we’ll start to […]

Categories
SQL Server

SSMS Productivity Boost with Multi Line Editing

One of the most time consuming tasks in Management Studio is repeating the same changes across multiple lines of a query. The answer to this? – Multi Line (or Column Mode) Editing. Here’s a quick post to explain what it is, how to do it, and examples to see it in action. What is multi […]

Categories
SQL

Utilising Bit Masks with Bitwise Operators

A few weeks back we looked at options for storing multiple boolean flag values in a table. One of the options we considered was the use of a Bit Mask where we packed multiple flags into a single field. When we have individual fields within a table, using and manipulating those is straightforward. However when we’ve got […]

Categories
SQL

Designing Long Running Procedures for Maintainability

Whilst we have front-end code which requires faster response times, there are also times we build code with the purpose of running for extended periods of time. Examples of this could be maintenance routine, or custom built queuing mechanisms. The way in which we design longer running processes like this can be key when it […]

Categories
T-SQL Tuesday

Belated T-SQL Tuesday #165 – Data Jobs Roles

Well I’m a little late to the party this month, I got my weeks mixed and was only reading about this month’s T-SQL Tuesday as the community was posting their responses. So here we go, finally. This month’s ask from Josephine was to consider our understanding or expectations from data job roles. When we see […]

Categories
SQL

Calculating String Lengths

We store a wide variety of data within our platforms, some of which will inevitably be string based. Along with that comes a need to perform manipulation of those strings. When slicing, combining, or manipulating strings one element which we need to consider is the length of the string. Here I wanted to have a […]

Categories
SQL

Recursive Functions and Limitations

When writing functions within SQL Server we sometimes have need to repeat an action multiple times until a given condition is met – also known as Recursion. There are a couple of common ways which this can be implemented which also have their different limitations. A little about recursion Firstly, why do we need recursion? […]

Categories
SQL

Schema Design for Bit Flags

When designing a data schema to store a variety of entities it can be common to require a selection of flags to be stored. There are different ways in which the data can be designed to accommodate this which I wanted to look at here. Examples of these fields could be an ‘Is Active’ flag […]

Categories
SQL

Ranking Function Reference

When processing data there is frequently a need to rank the outputs. This could be to limit a selection of records to return, or provide a type of leader-board for reporting. There are a number of ranking functions within the SQL language which we’ll look at here with examples and outputs. We’ll start with some […]

Categories
SQL

Alternative to Binary Case Statements

When outputting data through a procedure it’s a common use case to add fields which have been calculated from existing data. One way to achieve this is using the CASE statement, however we don’t always need that level of complexity, particularly when we’re looking for a binary result such as ‘Yes’ / ‘No’. An alternative […]