The following example uses T-SQL to merge two tables in SQL Server. It uses the VALUES
table value constructor as the source table.
Category: SQL Server
3 Ways to Convert an Integer to Decimal in SQL Server
Here are three options for converting an integer to a decimal value in SQL Server using T-SQL.
Continue readingSQL Server SHOW TABLES Equivalent
Every now and then I find myself typing SHOW TABLES
in SQL Server, expecting to get a list of tables.
That would make perfect sense if I was using MySQL or MariaDB. But SQL Server/T-SQL doesn’t have a SHOW TABLES
statement like MySQL or MariaDB, so it never works. And I keep forgetting. But fortunately, SQL Server does have alternatives.
Here are five options for getting a list of tables in SQL Server. These can be used whenever you’re trying to find that elusive SHOW TABLES
statement in SQL Server.
Fix Msg 512 “Subquery returned more than 1 value” in SQL Server
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 reading5 Ways to Select Rows with the Minimum Value for their Group in SQL
Here are five options for using SQL to return only those rows that have the minimum value within their group.
These examples work in most major RDBMSs, including MySQL, MariaDB, Oracle, PostgreSQL, SQLite, and SQL Server.
Continue reading3 Ways to Select the Row with the Minimum Value in SQL
Here are three examples of using SQL to find and select the row with the minimum value in a given column.
The examples work in most major RDBMSs, including MySQL, MariaDB, PostgreSQL, SQLite, Oracle, and SQL Server.
Continue reading7 Ways to Find Duplicate Rows in SQL Server while Ignoring any Primary Key
Here are seven options for finding duplicate rows in SQL Server, when those rows have a primary key or other unique identifier column.
In other words, the table contains two or more rows that share exactly the same values across all columns except for its unique identifier column.
Continue reading4 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 reading5 Ways to Select Rows with the Maximum Value for their Group in SQL
Here are five options for using SQL to return only those rows that have the maximum value within their group.
These examples work in most major RDBMSs, including MySQL, MariaDB, Oracle, PostgreSQL, SQLite, and SQL Server.
Continue reading