SQL code from MS SQL Server Class 2013