Learning Mandarin: Five – about me?

This is the sixth in a series of posts where I'm looking at how the Chinese view numbers, often from a superstitious basis.

Five

The Chinese character for five (Wǔ) is shown on the right hand side of the main image above.

The number five is slightly on the lucky side of neutral in Chinese, where people believe there are five blessings: luck, prosperity, wealth, longevity, and happiness.

Similarly, it has been associated with the five elements: water, earth, fire, wood, and metal. There is some past association with emperors.

It sounds a bit like the word 吾 (Wú) which means "I", "my", or "me".

While that's all good, it also sounds like 无 (Wú) which is more like "nothing" or "not" or "without". That has the possibility of being either good or bad.

Learning Mandarin

I'll write more soon on the best methods for learning. If you want to get a taste for it in the meantime though, my current favorite site is iTalki, and my favorite teacher by far is Amy He. If you decide to try it, click here and it's cheaper for both you and me.

T-SQL 101: #31 Understanding batches, scripts, and GO

The image below shows a T-SQL script.

It's an example of contents of a file that you could have on your disk so the entire thing could be called MyProgram.sql. Inside this script file, we've got a few different types of things happening here.

The word script applies to all of the contents of the file.

You can see the word GO there a number of times. It's a special word that's not actually a T-SQL keyword. It's a batch separator. It only has meaning to the tool you're using to execute queries, like SQL Server Management Studio or Azure Data Studio.

When you execute a script, it might look like it's all sent to the server at once, but that's not what happens. SSMS finds the word GO, breaks the script up into batches, and sends them to the server, individually.

So, in this case, the following four batches are sent, one batch at a time:

  1. USE master;
  2. CREATE DATABASE Interesting;
  3. USE Interesting;
  4. CREATE TABLE dbo.Information
    ( InformationID int,
    Thoughts varchar(20)
    );
    INSERT INTO dbo.Information
    VALUES (1, 'Hello');

We describe Batch 4 as having two statements, the CREATE TABLE statement, and the INSERT statement.

What is GO really?

I mentioned that GO is a batch separator. You could actually use almost anything instead of GO. In the Tools>Options>Query Execution>SQL Server section in SSMS, you could change it to something else.

I'd suggest that you avoid changing it because you want your scripts to run on other machines and programs as well, and GO is the standard batch separator.

I have a Star Trek friend. All his scripts have the word ENGAGE instead of GO.

And of course a nasty trick for new DBAs is to change it to the word SELECT and watch them try to work out what's wrong.

Learning T-SQL

It's worth your while becoming proficient in SQL. If you'd like to learn a lot about T-SQL in a hurry, our Writing T-SQL Queries for SQL Server course is online, on-demand, and low cost.

Learning Mandarin: Four – death…

This is the fifth in a series of posts where I'm looking at how the Chinese view numbers, often from a superstitious basis.

Four

The Chinese character for four (Sì) is shown on the right hand side of the main image above.

Four is universally regarded as a bad number in Chinese culture. Once again, that's because it sounds like other words.

In particular, four sounds like 死 (Sǐ) which means "death". It's similar in Cantonese where the word is sei, it's the same issue. It's considered an unlucky number because of this.

You'll find buildings in Asia that don't have a floor 4 (similar to how many Western buildings years ago had no floor 13). Some buildings take it even further and have no floor 4, 14, 24, 34, and so on.

Four is so frowned upon that people avoid saying it, and don't display it anywhere. People will get upset if they're issued an ID or credit card that has the number 4 in it.

Learning Mandarin

I'll write more soon on the best methods for learning. If you want to get a taste for it in the meantime though, my current favorite site is iTalki, and my favorite teacher by far is Amy He. If you decide to try it, click here and it's cheaper for both you and me.

Book Review: Power BI MVP Book

Over the last few months, one of my Kiwi buddies (and fellow member of both the MVP and Microsoft Regional Director programs) Reza Rad has been organizing a bunch of us to write a book that's a collection of ideas from a number of MVPs. It's the Power BI MVP Book.

There are a whole lot of authors from a whole lot of different countries: Reza Rad, Anil Maharjan, Indira Bandari, Liam Bastick, Ken Puls, Jesus Gil, Thomas LeBlanc, Ike Ellis, Matt Allington, Leila Etaati, Markus Ehrenmüller, Ashraf Ghonaim, Eduardo Castro, Manohar Punna, Treb Gatte, Gilbert Quevauvilliers, Michael Johnson, Shree Khanal, Asgeir Gunnarsson, Greg Low, Gogula Aryalingam.

I've done these types of books before with the SQL Server MVP Deep Dives pair of books. They are a different book in that you're not getting a single story throughout the book. Instead, you're getting a whole set of independent chapters on a variety of topics related to Power BI.

The general idea of these books is to support a charity, and that's where anything that I would have earned from them is going.

Bottom line?

I hope you find this book useful. There is both a paperback and a Kindle edition. The Kindle eBook is far cheaper.

Greg's rating: you decide

Note: as an Amazon Associate I earn (a pittance) from qualifying purchases but whether or not I recommend a book is unrelated to this. One day it might just help cover some of my site costs. (But given the rate, that's not really likely anyway).

SDU Tools: Calculate string length in SQL Server T-SQL

If you ask SQL Server developers how to calculate the length of a string in T-SQL, most would tell you immediately that you need to use the LEN() function. What most don't realize though, is that it doesn't actually work properly.

The T-SQL LEN() function ignores any trailing spaces in a string.

That's not how a string length function should work, or how it works in most languages. So, in our free SDU Tools for developers and DBAs, we added a simple tool that works properly. It's called StringLength.

Nothing complex. It takes a string, and returns its length in characters.

Find out more

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

Access to SDU Tools is one of the benefits of being an SDU Insider, along with access to our other free tools and eBooks. Please just visit here for more info:

http://sdutools.sqldownunder.com

 

T-SQL 101: #30 Changing databases with the USE statement in T-SQL

Take a look at the following query:

I've asked for a list of the databases from the sys.databases view. But rather than executing it against whichever database I was already connected to, I've said USE master; to change to the master database.

The command will be sent to the master database instead of any other database that I might have been connected to. At that point, master becomes my "current database".

Then by saying USE PopkornKraze; I've asked SQL Server to change to working with the PopkornKraze database. The commands that execute after that USE statement will be sent to the server, with PopkornKraze as the current database.

Did I need to change?

If you look at the third query, I've used a three part name to refer to the view in the master database. So even though the command will be sent with the PopkornKraze database as the current database, I'm referring to a view in the master database.

Learning T-SQL

It's worth your while becoming proficient in SQL. If you'd like to learn a lot about T-SQL in a hurry, our Writing T-SQL Queries for SQL Server course is online, on-demand, and low cost.

Learning Mandarin: Three – important stages of life?

This is the fourth in a series of posts where I'm looking at how the Chinese view numbers, often from a superstitious basis.

Three

The Chinese character for three (Sān) is shown on the right hand side of the main image above. It's three single lines (probably originally sticks).

Generally, the number three is regarded as a good number in Chinese culture. Many times, meanings of Chinese numbers are related to other words they sound like. While three doesn't sound all that close to 生 (shēng), in Cantonese the word is sāang, which is much closer.

Either way, 生 means life and is often directly related to birth.

出生 (Chūshēng) is to be born and even though Chinese aren't really into birthdays (at least traditionally), 生日 (Shēngrì) is the word for "birthday".

Many historical tales in Chinese use three in a positive way. You'll come across restaurants like "three kings". Some see it as a heavenly number, associated with prosperity.

Unfortunately though, there is another meaning associated with three. While in Cantonese, it sounds a bit like sāang, it also sounds a bit like sāam, which relates to separating or breaking up with someone or something. So that's the downside of this number.

Learning Mandarin

I'll write more soon on the best methods for learning. If you want to get a taste for it in the meantime though, my current favorite site is iTalki, and my favorite teacher by far is Amy He. If you decide to try it, click here and it's cheaper for both you and me.

SDU Tools: Calculate Time Period Dimension Columns in SQL Server T-SQL

In my last SDU Tools post, I described a tool for calculating date dimension columns. While dates are often enough, in many data warehouses, you also need to allocate time periods across each day as well. To make that very easy, in our free SDU Tools for developers and DBAs, we added a tool called TimePeriodDimensionColumns.

This tool is a table-valued function that takes a time (actual time of the day), and the length of each time period, in minutes. In the example in the main image above, I've asked for 8:34PM and I've said that each period is 15 minutes long.

You can also see the list of returned columns in the main image above.

To make it easy to create a time period dimension for an entire day, we also added a tool called GetTimePeriodDimension.

Find out more

You can see TimePeriodDimensionColumns in action in the main image above, and see both tools in the videos here:

Access to SDU Tools is one of the benefits of being an SDU Insider, along with access to our other free tools and eBooks. Please just visit here for more info:

http://sdutools.sqldownunder.com

 

T-SQL 101: #29 Calling user-defined functions in SQL Server T-SQL queries

Important concepts in any development are reusing code, and abstraction. Look at the first WHERE clause here:

I've asked SQL Server to return rows where the CreditRatingID is the one that has the maximum rating. I might not know how to find the maximum rating but if there is code that finds it for me (i.e. dbo.GetMaximumRating()), I don't need to know that.

This is an example of a function that retrieves a value, and then I can use the value in my own query, without having to copy all the code that's needed, and without even having to know how it works.

When a function only returns a single value, we call it a scalar function.

If the function is user-written code (rather than system-supplied code in SQL Server), we call it a scalar user-defined function.

Note: There have been some performance problems over the years that are related to using T-SQL scalar user-defined functions, but we'll talk about that another day.

Table-Valued Functions

As well as just returning single values, functions can also return entire tables of data.

In the second query in the image above, a table-valued function (TVF) that takes a single parameter (i.e. the StateCode), and returns details of the cinemas in that state. Again I don't need to know how the code works or what it does. I can just use it.

Once again, there are system-supplied table-valued functions and user-defined table-valued functions.

Learning T-SQL

It's worth your while becoming proficient in SQL. If you'd like to learn a lot about T-SQL in a hurry, our Writing T-SQL Queries for SQL Server course is online, on-demand, and low cost.

Learning Mandarin: Two – easy going or reckless?

This is the third in a series of posts where I'm looking at how the Chinese view numbers, often from a superstitious basis.

Two

The Chinese character for two (Èr) is shown on the right hand side of the main image above. It's two single lines (probably originally sticks).

Generally, the number two is regarded as a good number in Chinese culture. Similar to the English saying, the Chinese have an equivalent saying for "good things some in pairs".

Two suggests happiness, joy, and luck. However, two can also represent stupid and reckless.

Because the Cantonese word for two is similar sounding to the word for "easy", two is also often associated with "easy". A good example is that the number 24 is often regarded as "easy death" or "reckless death". We'll talk about 4 later.

Learning Mandarin

I'll write more soon on the best methods for learning. If you want to get a taste for it in the meantime though, my current favorite site is iTalki, and my favorite teacher by far is Amy He. If you decide to try it, click here and it's cheaper for both you and me.