In PostgreSQL, RPAD()
is a function that enables us to add padding to the right part of a string.
Author: Ian
LPAD() Function in PostgreSQL
In PostgreSQL, LPAD()
is a function that enables us to add padding to the left part of a string.
Add a Time Zone Offset to a datetime2 Value in SQL Server (T-SQL)
In SQL Server, the TODATETIMEOFFSET()
function was specifically designed to return a datetimeoffset value from a datetime2 value.
Given the fact that the datetime2 data type doesn’t actually support time zone offsets, and datetimeoffset must contain the offset, the TODATETIMEOFFSET()
function allows you to specify a time zone offset to use.
This article provides some examples to demonstrate.
Continue readingHow to Format Numbers in MariaDB
MariaDB has the FORMAT()
function, which formats a number based on the given format string.
It returns the number as a formatted string, with thousands and decimal separators in the appropriate position and rounds the result to the specified decimal position.
You can optionally specify a locale value to format numbers to the pattern appropriate for the given region.
Continue readingHow to Concatenate Strings in SQL
Most of the major RDBMSs provide several options for concatenating two or more strings.
- There’s the
CONCAT()
function, which concatenates its arguments. - There’s also a
CONCAT_WS()
that allows you to specify a separator that separates the concatenated strings. - And there’s also a string concatenation operator, which allows us to concatenate its operands.
Below are examples of each method.
Continue readingGet the Number of Failed Login Attempts for a Login due to a Wrong Password in SQL Server (T-SQL)
In SQL Server, you can use the LOGINPROPERTY()
to return information about login policy settings.
This includes being able to return data for bad password attempts, as well as the time of the last failed login attempt due to a bad password.
Continue readingFormat Numbers with Commas in PostgreSQL
In PostgreSQL, we can use the TO_CHAR()
function to format numbers in a given format. This includes formatting numbers with commas in the relevant location.
PostgreSQL also has a money
data type, which outputs the value using the current locale. This can include commas in the appropriate place, based on the locale being used.
How to Get the Day, Month, and Year from a Date in SQL
Most of the major RDBMSs have functions that enable us to extract the day, month, and year from datetime values.
Some RDBMSs provide multiple ways to do this, and others are more limited. Below are examples of extracting the day, month, and year from date values in some of the most popular RDBMSs.
Continue readingFORMAT() Examples in MySQL
In MySQL, the FORMAT()
function returns a number formatted to a specified number of decimal places.
It includes group separators and a decimal separator where applicable.
Continue readingHow to Format Numbers with Commas in SQL Server
SQL Server provides us with a quick and easy way to format numbers with commas inserted at the relevant place. For example, 1234.56 can become 1,234.56. Or it can become 1.234,56, if that’s the locale that you’re using.
Continue reading