Sql-Server

SQL: EXEC AS USER on EXEC Statements

SQL: EXEC AS USER on EXEC Statements

The WITH EXECUTE AS clause was a great addition for defining stored procedures and functions, to change the execution context, just for the duration of the stored procedure or function. For example:

CREATE PROC SomeSchema.SomeProc
WITH EXECUTE AS USER = 'Fred'
AS
... 

Mostly I use this with the OWNER option:

CREATE PROC SomeSchema.SomeProc
WITH EXECUTE AS OWNER
AS
... 

It’s also useful during testing, where I can temporarily change my execution context during testing. For example:

EXEC AS USER = 'Fred';

\-- Try some code here while running as Fred

REVERT;

But the option that most people don’t realize is possible, is that you can set the execution context for a single execution like this:

2026-04-10

SDU Tools: List User Heap Tables in SQL Server

SDU Tools: List User Heap Tables in SQL Server

It’s common advice that most SQL Server tables should have a clustered index. There are some exceptions to this but it’s a pretty general rule, and if in doubt, you should follow it. (Note that this is not the same as having a primary key).

I regularly come across tables without clustered indexes for all the wrong reasons. So, in our free SDU Tools for developers and DBAs, we added a tool that can look for user tables that don’t have a clustered index. No surprise, it’s called ListUserHeapTables because a table without a clustered index is a heap.

2026-04-08

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

SSRS and Fabric Paginated Reports: Be very careful with using "c" formatting for currency

SSRS and Fabric Paginated Reports: Be very careful with using "c" formatting for currency

While on site this week, another common problem that I see everywhere arose again.

When you need to format currency, you use the “c” format right? It’s in nearly every set of course materials I’ve ever seen. And people do it in almost every demonstration.

But so often, that’s wrong!

When you do this, you’re telling the system to display the monetary value using the local currency.

Is that correct though?

2026-03-21

Opinion: Are certification exams useful for experienced people?

Opinion: Are certification exams useful for experienced people?

Over the years, I’ve seen so many discussions regarding the certification process and exams. I’ve seen posts from many people that are very experienced with products saying they can’t see any point in the certification exams and also argue that competencies in the Microsoft Partner program shouldn’t be based on exams. They feel these people should somehow just be recognised for their other contributions.

Grandfathering

Regarding the certification process, I don’t agree that anyone should be just grandfathered in. Any of the people that have a great deal of knowledge and experience really should be able to just take the exams and be done with it.

2026-03-17