The Bit Bucket

SDU Tools: Truncate trailing zeroes in SQL Server T-SQL

Often when I convert a decimal number to a string in T-SQL, I want the simplest version of the number. I really don’t want any trailing zeroes (i.e. at the end of the number).

In our free SDU Tools for developers and DBAs, we added a function to do just that: TruncateTrailingZeroes.

The function just takes one parameter: the number to be processed.

You can use our tools as a set or as a great example of how to write functions like these.

2019-11-20

Book Review: The Future of Capitalism by Paul Collier

I’ve mentioned before that Orin Thomas tends to give me many good book recommendations. The Future of Capitalism by Paul Collier is another of Orin’s recommendations. I notice from the cover that it’s also highly recommended by Bill Gates. So it had to be worth a look.

I ended up listening to this via an Audible audio book. It’s quite a long book at around 9 hours 26 minutes.

Overall, I loved this book. I’d have to say though, that it took me quite a while to get into it. I just didn’t find the first chapters all that compelling. But strangely, I then really did get into it.

2019-11-19

T-SQL 101: 44 Trimming whitespace from strings in SQL Server

I often need to remove spaces from the front or back (or both) of strings. For a long time, the two functions we had for that were LTRIM (for left trim) and RTRIM (for right trim).  You can see them in the first two SELECT statements here:

For as long as I’ve used SQL Server though (also a long time), people have been asking for a TRIM function. Most developers were tired of endlessly writing LTRIM(RTRIM()) to do that. In SQL Server 2017 though, we did finally get a TRIM function. It trims both the left and right hand sides of a string.

2019-11-18

Snowflake for SQL Server Users - Part 15 - Table types

Snowflake has a richer set of options for how tables are created, than we have in SQL Server.

CREATE TABLE Variants

As well as a CREATE TABLE statement as you would already be familiar with in SQL Server, Snowflake offers these variants:

CREATE TABLE tablename AS SELECT

This is basically similar to a SELECT INTO in SQL Server. It executes the SELECT query and creates a table from the results (including the data).

2019-11-15

SQL: Sending email to an operator rather than a recipient in SQL Server

I was answering a question on a forum the other day, and the person asking the question was puzzled about how to send an email to an operator (i.e. msdb operator) rather than to just any other email address.

The reason he wanted to do that was that he wanted to use the Agent operator system to define a name. He didn’t want to hard-code a recipient name in his code. By having it as an operator, it could be changed later, independent of the code.

2019-11-14

SDU Tools: Single space words in SQL Server T-SQL

We’ve got a lot of very useful string-related functions in SDU Tools. This is another one. At times, there’s a need to remove excess spaces between words in strings. In our free SDU Tools for developers and DBAs, we added a function to do just that: SingleSpaceWords.

The function just takes one parameter: the string to be processed.

Find out more

You can see it in action in the main image above, and in the video here:

2019-11-13

Spatial Data: If you are working with Australian mapping data, Mappify.io is worth knowing about

I spend quite a bit of each year working with spatial data (i.e. mostly mapping data but sometimes other data). One of the constant challenges is where to find the spatial data. Another challenge is where to find services that can help you to work with the data.

For Australian data, if you haven’t considered Mappify.io, I think you should take a look.

You need to create an account before you start but it’s free to create an account to try it out. Then there are a number of services.

2019-11-12

T-SQL 101: 43 Concatenating strings in SQL Server

Joining together strings is called concatenating strings. In the first example here you can see SELECT hello, plus NULL, plus there. Now the trick with this, though, is that NULL is a bit of a challenge.

Note that the outcome of that first select statement is NULL is just NULL. As soon as you concatenate something with NULL, you would end up with NULL as the overall answer.

2019-11-11

Snowflake for SQL Server Users - Part 14 - Internal storage in Micropartitions

If you want to learn a lot about how Snowflake works internally, it’s worth spending some time reading the ACM whitepaper that described the service.

It describes the overall structure of the service, and then describes how data is stored, followed by a description of how the encryption of the data within the service is accomplished. (I’ll talk more about the management of encryption keys in a later blog post).

2019-11-08

SQL: Rolling up or archiving transactions past a cutoff date in T-SQL

Another question that I recently saw on Stack Overflow was asking how you SELECT a bunch of transactions back past a cutoff date, add them up, INSERT a roll-up row, and then delete the old ones. The concern was with how you make sure the ones you are deleting are the same rows that you are rolling up (or totalling). Someone else might UPDATE or INSERT a row at the same time.

2019-11-07