How 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.

Continue reading

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 reading

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 reading

Fix Msg 8117 “Operand data type varchar is invalid for sum operator” in SQL Server

If you’re getting SQL Server error Msg 8117 with the message Operand data type varchar is invalid for sum operator, it’s because you’re passing the wrong data type to an operator or function.

In this case, the error indicates that we’re passing a string to the SUM() function. The SUM() function does not operate on strings. It only works on numeric types.

The same error (Msg 8117) can also occur in other contexts – it’s not limited to the SUM() function.

Continue reading