title: Finding average ,minumum,maximum while column names stored in temp variables in sql stored procedure
body: <p>I have one table whcih is valuedata having multiple columns as <code>a,b,c,d,e,f</code>
  I want to take <code>min</code>,<code>max</code>,<code>avg</code> for some columns not all which comes form inputs params from stored procedure.
  my problems is when I find <code>avg(@column1)</code> it giving me output as a not values of that column so how do I solve this </p>
  
  <pre><code>
  --[MinMaxAvg_test]  'A,b,c'
  
      ALTER PROCEDURE [dbo].[MinMaxAvg_test]
      @Parameters varchar(Max)
  
      AS  
      BEGIN
  
      Declare @ParaCount int
      declare @Para varchar(10)
  
      Declare @SelectedParametr_Table table(ID int identity(1,1), Parameter varchar(20))
      Insert into @SelectedParametr_Table SELECT Item FROM dbo.SplitString(@Parameters, ',')
  
       set @ParaCount=1
          While(@ParaCount &lt;=(Select count(Parameter) from @SelectedParametr_Table))
              Begin
          set @Para=null
           select @Para=Parameter from @SelectedParametr_Table where id=@ParaCount
  
          Select top(1) min(@Para) as MIN,max(@Para) As MAX,avg(@Para) as AVG from VALUEDATA
  
        set @ParaCount=@ParaCount+1
  
        end
          set @ParaCount=1
  
      END
  
  </code></pre>
  
  <pre><code>Output of this I am getting as follows :
               MIN   MAX  AVG
                A     A    A
  
               MIN   MAX  AVG
                B     B    B 
  
               MIN   MAX  AVG
                C     C    C 
  </code></pre>
  
  <p>I want values for this columns how to do this can any one tell me</p>