我有一个存储过程,它是用C#编写的:
SqlConnection scn = new SqlConnection("context connection=true;");
SqlCommand scm = new SqlCommand("Select * from EPMS_Filters",scn);
SqlDataAdapter sda = new SqlDataAdapter(scm);
DataSet ds = new DataSet();
//template for select Query.
String SelectQry = "select convert(varchar,TimeStamp,101) as TimeStamp, avg({0} from EPMSDataTable where timestamp between '{1}' and '{2}' group by convert(varchar,timestamp,101)";
String filters = "";
//select clause part which contains simple columns select col1, col2...
sda.SelectCommand.CommandText = "Select column_name from information_schema.columns where table_name = 'EPMSDataTable' and column_name <> 'timestamp'";
sda.Fill(ds, "SimpleFilters");
foreach (DataRow dr in ds.Tables["SimpleFilters"].Rows)
{
String fName = dr[0].ToString();
filters += dr[0] + ")as " + dr[0] + ", avg(";
}
filters = filters.TrimEnd(", avg(".ToCharArray()); //remove last ','
scm.CommandText = String.Format(SelectQry,filters,start.ToString(),end.ToString());
scn.Open();
SqlContext.Pipe.Send(scm.ExecuteReader());
scn.Close();
有没有任何方法或工具可以将这段代码转换成一个 SQL 存储过程代码呢?还是说我必须手写重写它呢?