In SQLite, we can use the IF EXISTS
clause of the DROP TABLE
statement to check whether the table exists or not before dropping it.
Find Non-Numeric Values in a Column in SQL Server
There may be occasions where you need to check a column for non-numeric values. For example, you discover that a column is a varchar
column when it really should be a numeric column.
This is easily done in SQL Server with the ISNUMERIC()
function.
3 Ways to List All Functions in PostgreSQL
Here are three options for listing out all functions in a PostgreSQL database.
Continue readingFormat a Phone Number in SQL Server (T-SQL)
Here are some examples of formatting phone numbers in SQL Server.
This includes examples of formatting numbers in E.164 format (for international numbers), prepending the country code and area code, as well as omitting leading zero from the country code when required.
Continue readingSUM() Function in SQL Server
In SQL Server, the SUM()
aggregate function returns the sum of a given expression.
It can also be used to return the sum of all distinct (unique) values in the expression.
SUM()
only works on numeric columns. Null values are ignored.
Fix Msg 8116 “Argument data type date is invalid for argument 1 of substring function” in SQL Server
If you’re getting SQL Server error Msg 8116 with text that reads Argument data type date is invalid for argument 1 of substring function, it’s because you’re passing the wrong data type to a function – in this case, the SUBSTRING()
function.
You could also see the same error (Msg 8116) in many other contexts – it’s not limited to the SUBSTRING()
function.
4 Ways to Check a Column’s Data Type in MariaDB
MariaDB provides multiple ways of returning the data type of a column. Here are four ways to get the data type of a given column in MariaDB.
Continue readingFix Msg 8114 “Error converting data type varchar to numeric” in SQL Server
If you’re getting SQL Server error Msg 8114 that reads something like Error converting data type varchar to numeric, it’s probably because you’re trying to perform a data type conversion that fails due to the value not being able to be converted to the destination type.
It’s not because you can’t convert that type to the new type. It’s because of the value itself.
Continue readingHow TRY_CAST() Works in SQL Server
In SQL Server, an often used function is CAST()
, which converts an expression of one data type to another. But if the cast doesn’t succeed, then it returns an error.
Enter TRY_CAST()
.
The TRY_CAST()
function doesn’t return an error if the cast fails. Instead, it returns NULL
.
There are some occasions however, where it will return an error.
Continue readingHow TRY_CONVERT() Works in SQL Server
In SQL Server, the TRY_CONVERT()
function is very similar to the CONVERT()
function, except that TRY_CONVERT()
doesn’t return an error if the conversion fails (CONVERT()
does).
Instead, the TRY_CONVERT()
function returns NULL
if the conversion doesn’t succeed.
There are some occasions however, where TRY_CONVERT()
will return an error.