SQL CONCAT

Transact-SQL (TSQL) Quick Tips – SQL CONCAT In many cases I need to bring together two separate fields to create a new field.  Whether it be for display purposes, informational or joining to another table, the ability to combine two fields into one comes up frequently in my day-to-day work. Starting with SQL Server 2012, … Read more

SQL Query Database Size

Transact-SQL (TSQL) Quick Tips – SQL Query Database Size I recently experienced a situation where disk space was close to capacity.  We manage a lot of databases and wanted to get a quick understanding of which particular databases were taking up the most space.  Using the following query, you can easily view the full list of databases on a specific server, … Read more

SQL UNION

The following post illustrates how to use the SQL UNION and SQL UNION ALL Operators. From time to time, I need to bring content from two separate tables together in a query.  Using the SQL UNION or SQL UNION ALL operators, I can combine this information using two SELECT statements, bringing the results together. SQL … Read more

SQL SELECT Nth Record

Transact-SQL (TSQL) Quick Tips – SQL SELECT Nth Record I recently needed to compare two month end data snapshots.  The data was organized in a historical table with monthly datasets, dating back several years.  The specific need was to query changes between the previous dataset and the most recent.  The task itself isn’t difficult.  What … Read more

SQL HAVING

Transact-SQL (TSQL) Quick Tips – SQL HAVING clause Here is a simple example of how the SQL HAVING clause works.  You can copy this code into your Query Window and EXECUTE as-is.  The code includes a #temp table with data to illustrate the functionality.  You can modify to suit your needs. The SQL HAVING clause specifies … Read more