MySQL CHAR() vs T-SQL CHAR(): What’s the Difference?

There are many functions that are included in both MySQL and SQL Server. However, just because both DBMSs share functions of the same name, doesn’t mean that those functions work exactly the same way.

Take CHAR() for example. Both MySQL and SQL Server include this function. Well technically, for SQL Server it’s actually a T-SQL function, but that’s beside the point. The point is that the MySQL CHAR() function provides more functionality than the T-SQL/SQL Server CHAR() function.

In particular, the MySQL version accepts multiple integers, whereas, the T-SQL version only accepts a single integer. The MySQL version also accepts a USING clause that allows you to specify which character set to use (the T-SQL version doesn’t have this clause).

Below are some examples of these differences.

Continue reading

SIGN() Examples in SQL Server

In SQL Server, the T-SQL SIGN() function returns the sign of a number. In other words, it indicates whether or not the value is a positive number, a negative number, or zero.

You provide the number as an argument when calling the function.

The function returns the following result, depending on whether the argument is positive, negative, or zero.

  • 1 if the number is positive
  • -1 if the number is negative
  • 0 if the number is zero

Continue reading

ROUND() Examples in SQL Server

In SQL Server, the T-SQL ROUND() function allows you to round a number to a specified length or precision.

You provide the number as an argument, as well as the length you’d like the number to be rounded to. The function also accepts an optional third argument that allows you to specify whether the number is rounded or truncated.

Continue reading