If you get error Msg 512 that reads “Subquery returned more than 1 value…” in SQL Server, it’s because you’re using a subquery that returns more than one value in a scenario where this is not allowed.
Continue readingTag: t-sql
4 Functions to Format a Number to 2 Decimal Places in SQL Server
When using T-SQL with SQL Server, we can format numbers using various methods, depending on our desired format.
Below are four functions that can be used to format a number to two decimal places in SQL Server.
Continue reading4 Ways to Check for Duplicate Rows in SQL Server
Here are four methods you can use to find duplicate rows in SQL Server.
By “duplicate rows” I mean two or more rows that share exactly the same values across all columns.
Continue reading3 Ways to Return Rows that Contain Alphanumeric Characters in SQL Server
Here are three examples of returning rows that contain alphanumeric characters in SQL Server.
Alphanumeric characters are alphabetic and numeric characters.
Continue readingDelete Duplicate Rows in SQL Server
The following example uses T-SQL to delete duplicate rows in SQL Server.
To be more specific, it deletes duplicate rows but keeps one. So if you have two identical rows, it deletes one of them and keeps the other. In other words, it de-dupes the table.
Continue readingHow to Get the Recovery Model of a Database in SQL Server using T-SQL
In SQL Server, a recovery model is a database property that controls how transactions are logged, whether the transaction log requires (and allows) backing up, and what kinds of restore operations are available. Databases can use one of the following three recovery models: simple, full, and bulk-logged.
You can query the sys.databases
catalog view to get a list of databases and their recovery models.
Fix Msg 241 “Conversion failed when converting date and/or time from character string” in SQL Server
If you’re getting SQL Server error Msg 241 that reads Conversion failed when converting date and/or time from character string, it’s probably because you’re trying to convert a string to a date/time value, but that particular string can’t be converted to the date/time type specified.
Continue readingHow NULLIF() Works in SQL Server
In SQL Server, the NULLIF()
expression checks the value of two specified expressions. It returns a null value if they’re equal, otherwise it returns the first expression.
Fix Msg 529 “Explicit conversion from data type int to xml is not allowed” in SQL Server
If you’re getting SQL Server error Msg 529 that reads something like Explicit conversion from data type int to xml is not allowed, it’s probably because you’re trying to perform a data type conversion that’s not permitted.
SQL Server doesn’t allow certain conversions. If you try to perform such a conversion, you’ll get this error.
Continue readingFix Msg 8116 “Argument data type varchar is invalid for argument 1 of session_context function” in SQL Server
If you’re getting SQL Server error Msg 8116 with the message Argument data type varchar is invalid for argument 1 of session_context function, it’s because you’re passing the wrong data type to a function – in this case the SESSION_CONTEXT()
function.