Azure-Sql-Db

SDU Tools: Nepali Date Processing in SQL Server T-SQL

SDU Tools: Nepali Date Processing in SQL Server T-SQL

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. Version 27 adds the first set of views and functions for working with Nepali dates. These are useful in Nepal and in a number of Buddhist-related areas.

The first tool added is a view called NepaliMonths. It returns the Nepali names for months. You can see it in the main image above.

2026-04-06

SDU Tools: Token Set Similarity in SQL Server T-SQL

SDU Tools: Token Set Similarity in SQL Server T-SQL

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. The TokenSetSimilarity function calculates token set similarity for two strings.

It answers the question: Do these two strings contain mostly the same words, even if the order, spacing, or repetition differs?

It is useful where word order varies, or extra or missing words are common. It can also help where character-level typos are less important than the presence of words.

2026-04-04

SDU Tools: Normalize for Search in SQL Server T-SQL

SDU Tools: Normalize for Search in SQL Server T-SQL

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. The NormalizeForSearch function normalizes a string to make it ready for search operations.

It makes strings comparable by stripping away differences that are usually meaningless for search or matching.

It helps to answer the question: If two strings refer to the same thing, what differences should I ignore before I even start comparing?

2026-04-02

SDU Tools: Levenshtein Distance in SQL Server T-SQL

SDU Tools: Levenshtein Distance in SQL Server T-SQL

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. The LevenshteinDistance function calculates the Levenshtein distance between two strings.

It essentially answers the question How far apart are these two strings in terms of character edits?, where edits are inserting, deleting, or substituting a character. In this calculation, each edit has a cost of 1.

Empty and NULL values on input return NULL.

2026-03-31

SDU Tools: Jaro Winkler Similarity in SQL Server T-SQL

SDU Tools: Jaro Winkler Similarity in SQL Server T-SQL

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. The JaroWinklerSimilarity function that we have added calculates the Jaro Winkler similarity for two strings.

It essentially answers the question Do these two short strings probably refer to the same thing, even if they aren’t exactly the same?.

It can be used where typos are common, or characters are transposed, and where prefixes matter more than suffixes. Empty and NULL values on input return NULL.

2026-03-29

SDU Tools: Formatting Bytes in SQL Server T-SQL

SDU Tools: Formatting Bytes in SQL Server T-SQL

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. The FormatBytes function can now be used to take a number of bytes, and to format it as a string, with appropriate units.

The calculation can be done using SI units (where 1000 bytes is one kB, or binary units where 1024 bytes is one KB. It can also output IEC based units like the kibibyte.

2026-03-27

SQL: Computed Columns: It's a matter of persistence

SQL: Computed Columns: It's a matter of persistence

Most SQL Server developers are aware that they can create computed columns. We do that by defining a column AS some expression like this:

CREATE TABLE Sales.OrderLines
(
    ...
    UnitPrice decimal(18, 2) NOT NULL,
    PickedQuantity decimal(18, 3) NOT NULL,
    LineTotal AS ROUND(UnitPrice * PickedQuantity, 2)
    ...
)

Each time the value from that LineTotal column is queried, the calculation is performed so the result can be returned. This makes sense when the value is changing regularly and the value is queried infrequently.

2026-03-07

SQL: Plan Cache Pollution - Avoiding it and Fixing it

SQL: Plan Cache Pollution - Avoiding it and Fixing it

While SQL Server’s plan cache generally is self-maintaining, poor application coding practices can cause the plan cache to become full of query plans that have only ever been used a single time and that are unlikely to ever be reused. We call this plan cache pollution.

Causes

The most common cause of these issues are programming libraries that send multiple variations of a single query. For example, imagine I have a query like:

2026-03-05

Echoes from the field 10 - What's in a name?

Echoes from the field 10 - What's in a name?

I always say that one of the things that I love about consulting or mentoring work is that I see things (mostly code) that I would have never have thought of.

Sometimes, it’s good information where I learn a new technique that I hadn’t considered. But most times, it’s just something weird that a client has done.

GUID Table Names

A good example of this was a site where every table had a GUID name. Yes, I’m talking about tables with names like:

2026-03-01

Mixing UNION and UNION ALL Operations

Mixing UNION and UNION ALL Operations

Recently, I saw a subtle coding issue related to the UNION operator. With SQL Server, the UNION operator combines two rowsets into a single rowset. If UNION ALL is used then all rows are returned. With just UNION without the ALL, only distinct rows are returned. All good so far.

One of the most common performance issues that I come across is where people have just used UNION where they should have used UNION ALL. That extra distinct operation is often not needed, yet often very expensive.

2026-02-27