LISTING 4: Step 1 of the sp_CrossTab Stored Procedure: Beginning of the SQL String DECLARE @sql AS varchar(8000), @NEWLINE AS char(1) SET @NEWLINE = CHAR(10) -- step 1: beginning of SQL string SET @sql = 'SELECT' + @NEWLINE + ' ' + @onrows + CASE WHEN @onrowsalias IS NOT NULL THEN ' AS ' + @onrowsalias ELSE '' END