LISTING 7: Step 4 of the sp_CrossTab Stored Procedure: End of SQL String SET @sql = @sql + @NEWLINE + 'FROM ' + @table + @NEWLINE + 'GROUP BY ' + @onrows + @NEWLINE + 'ORDER BY ' + @onrows -- PRINT @sql + @NEWLINE -- For debug EXEC (@sql) GO