In SQL Server, you can use the T-SQL FORMAT()
function to format a time data type. However, if you need to add the AM/PM designator, you’ll need to use a different data type. This is because the time data type is specifically based on a 24 hour clock, and therefore the time is formatted as such.
Tag: how to
How to Format Numbers as Currency in SQL Server (T-SQL)
In SQL Server, you can use the T-SQL FORMAT()
function to format a number as a currency.
The FORMAT()
function allows you to format numbers, dates, currencies, etc. It accepts three arguments; the number, the format, and an optional “culture” argument. This article specifically deals with using the format argument to specify a currency.
How the FORMAT() Function Works in SQL Server (T-SQL)
In SQL Server, you can use the T-SQL FORMAT()
function to return values such as numbers and dates as formatted strings.
You provide the value to be formatted, and you specify the format to use. The function accepts an optional argument that allows you to specify a culture to use when formatting the value.
Continue readingCreate a SQL Server Database with Azure Data Studio
Here, I explain how to use Azure Data Studio (formerly SQL Operations Studio) to create a database in SQL Server.
In my case, I’m running SQL Server on a Mac (via a Docker container), but these instructions are generic and should work exactly the same way on Linux and Windows.
This tutorial assumes you already have Azure Data Studio installed on your machine, and you’ve connected to your SQL Server instance. If you don’t have Azure Data Studio installed on your machine, here are instructions for installing it on a Mac and connecting to SQL Server via Docker. The Azure Data Studio installation is pretty straightforward (you install it just like any other software), so if you’re on Linux or Windows, you shouldn’t have any issues.
How to Restore a SQL Server Database on a Mac using Azure Data Studio
Restoring a database is a piece of cake with Azure Data Studio. It’s a similar process to doing it with SQL Server Management Studio. Simply click Restore and follow the prompts.
This restore process allows you to navigate through the computer’s file system to locate the .bak file. This .bak file contains a backup of the database you want to restore. So when SQL Server restores the database, it’s using the .bak file to do so.
However, if you’re running your SQL Server instance inside a Docker container (which of course, you would be if you’re running SQL Server on Mac or Linux), there’s something you need to be aware of if your backup file is located outside the Docker container.
How to Install Azure Data Studio on a Mac
Azure Data Studio (previously known as SQL Operations Studio) is a free tool that you can use to manage SQL Server. It uses a graphical user interface (GUI) that helps you view the various databases and objects within a SQL Server instance. It can run on Windows, macOS, and Linux, and it’s also designed to be used with Azure SQL Database, and Azure SQL Data Warehouse.
Here I explain how to install Azure Data Studio onto a Mac, then how to use it to connect to SQL Server.
3 Ways to Detect if a String Matches a Regular Expression in MySQL
MySQL has a number of functions and operators that allow us to perform operations using regular expressions (regex). This article presents two operators and one function that enable us to find out if a string matches a regular expression specified by a given pattern.
These regex functions and operators are:
These are all basically equivalent, as the operators (the second two) are both synonyms of the function (the first one). In any case, you can see examples of all three in action below.
How the MATCH() Function Works in MySQL
In MySQL, the MATCH()
function performs a full-text search. It accepts a comma separated list of table columns to be searched.
The table/s must have a FULLTEXT
index before you can do a full-text search against them (although boolean queries against a MyISAM
search index can work — albeit slowly — even without a FULLTEXT
index).
You can create a FULLTEXT
index when creating the table (using the CREATE TABLE
statement), or you can use the ALTER TABLE
statement or the CREATE INDEX
statement if the table already exists.
By default, the search is case-insensitive. To perform a case-sensitive search, use a case-sensitive or binary collation for the indexed columns.
How the SOUNDS LIKE Operator Works in MySQL
In MySQL, you can use the SOUNDS LIKE
operator to return results that sound like a given word.
This operator works best on strings in the English language (using it with other languages may return unreliable results).
How NOT LIKE Works in MySQL
In MySQL, you can use NOT LIKE
to perform a negation of the LIKE
operator. In other words, NOT LIKE
returns the opposite result to LIKE
.
If the string matches the pattern provided, the result is 0
, otherwise it’s 1
.
The pattern doesn’t necessarily need to be a literal string. This function can be used with string expressions and table columns.