I posted a question yesterday about how to SELECT different groups of data from one table into several columns [url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=32907[/url]. I think i've figured that out. now, i'm having problems returning the query! After running the procedure, which uses dynamic sql, I got a table with 23 records (expected), but no columns! So as an experiment, i proceeded to change the query so that the records are selected into a new table, and I do get what i want. So what is wrong? i read somewhere about setting nocount on, and i tried that too but to no avail.The codes are quite long but anyway i include them below.ALTER PROCEDURE dbo.tryA( @Array varchar(1000) ) ASset nocount ondeclare @separator_position int -- This is used to locate each separator characterdeclare @array_value varchar(1000) -- this holds each array value as it is returneddeclare @W intDECLARE @SQL1 varchar(3000)DECLARE @SQL2 varchar(3000)DECLARE @SQL3 varchar(1000)DECLARE @SQL varchar(8000)DECLARE @i varchar(20)DECLARE @p intSET @W=0SET @p=0set @array = @array + ','SET @SQL3 = ' WHERE (sP.Class = ''03S33'')'while patindex('%' + ',' + '%' , @array) <> 0 begin select @separator_position = patindex('%' + ',' + '%' , @array) select @array_value = left(@array, @separator_position - 1) select @array = stuff(@array, 1, @separator_position, '')SET @i=LTRIM(RTRIM(STR(@p)))IF @p=0BEGINSET @SQL1='SELECT t0.StudentId, sp.STUDENT_NAME, t0.Assmt_Marks As c0'SET @SQL2=' FROM dbo.MA_test_Results t0 INNER JOIN dbo.studentProfile sP on t0.StudentId=sP.student_nric AND t0.Assmt_Id='+@array_valueENDELSEBEGINSET @SQL1= RTRIM(@SQL1)+',t'+@i+'.Assmt_Marks As c'+@iSET @SQL2= RTRIM(@SQL2)+' INNER JOIN dbo.MA_test_Results t'+@i+' ON t'+@i+'.StudentId=t0.StudentId AND t'+@i+'.Assmt_Id='+@array_valueENDSET @p=@p+1endSET @SQL1=RTRIM(@SQL1)+' INTO marks'SET @SQL=RTRIM(@SQL1)+RTRIM(@SQL2)+RTRIM(@SQL3)EXEC(@SQL)SET nocount off