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: mssql
4 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 reading3 Ways to Get a List of Databases in SQL Server (T-SQL)
Below are three ways we can use T-SQL to return a list of databases in SQL Server.
Continue readingSHOW DATABASES Equivalent in SQL Server – sp_databases
There are several ways to show a list of databases in SQL Server. Probably the easiest way is to use the sp_databases
stored procedure.
The sp_databases
stored procedure is a kind of SQL Server equivalent to the SHOW DATABASES
command that can be used with DBMSs such as MySQL and MariaDB. OK, maybe they aren’t strictly equivalents, but based on their ease of use, they could be viewed as such from a user’s perspective.
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 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 readingGet the Current Login ID in SQL Server (T-SQL)
You can use the SUSER_ID()
function to return the login identification number of the current user.
You can also use it to return the login ID of another user.
This is similar to returning the current login name, except here we’re returning the ID instead.
Continue readingReturn the Current Workstation Name that’s Connected to SQL Server (T-SQL)
Occasionally you might find yourself in the situation where you need to get the name of the current workstation that’s connected to SQL Server.
For example, maybe you have a stored procedure that inserts data, and you want to record the name of the workstation that inserted the data.
In such cases, you can use the HOST_NAME()
function.
This is not to be confused with getting the server name.
Continue reading