title: Is there anyway of converting c# function to sql server stored procedure?
body: <p>I have a stored procedure which is written in c#:</p>
  <pre><code>SqlConnection scn = new SqlConnection(&quot;context connection=true;&quot;);
          SqlCommand scm = new SqlCommand(&quot;Select * from EPMS_Filters&quot;,scn);
          SqlDataAdapter sda = new SqlDataAdapter(scm);
          DataSet ds = new DataSet();
          
  
          //template for select Query.
          String SelectQry = &quot;select convert(varchar,TimeStamp,101) as TimeStamp, avg({0} from EPMSDataTable  where timestamp between '{1}' and '{2}' group by convert(varchar,timestamp,101)&quot;;
          String filters = &quot;&quot;;
  
          //select clause part which contains simple columns select col1, col2...
          sda.SelectCommand.CommandText = &quot;Select column_name from information_schema.columns where table_name = 'EPMSDataTable' and column_name &lt;&gt; 'timestamp'&quot;;
          sda.Fill(ds, &quot;SimpleFilters&quot;);
          foreach (DataRow dr in ds.Tables[&quot;SimpleFilters&quot;].Rows)
          {
              String fName = dr[0].ToString();
              filters += dr[0] + &quot;)as &quot; + dr[0] + &quot;, avg(&quot;;
          }
  
          filters = filters.TrimEnd(&quot;, avg(&quot;.ToCharArray()); //remove last ','
  
          scm.CommandText = String.Format(SelectQry,filters,start.ToString(),end.ToString());
          scn.Open();
          SqlContext.Pipe.Send(scm.ExecuteReader());
          scn.Close();
  </code></pre>
  <p>Is there anyway or some tool that can convert this code to an sql stored procedure code? Or do I have to rewrite it by hand?</p>