日期:2014-05-18  浏览次数:20710 次

怎么把下面的功能写成存储过程
如下,想把下面的代码转成存储过程,恳请指点,谢谢。

 
  string sql = "";
 
  DataTable dt = Conn.BindTable("SELECT distinct cellname FROM " + strTable1 + " WHERE normdatetime >= dateadd(hh,-10,getdate()) and normdatetime <= GetDate()");  
  if (dt.Rows.Count != 0)
  {
  for (int i = 0; i < dt.Rows.Count; i++)
  {
  string strcellname = dt.Rows[i]["cellname"].ToString().Replace("'", "''").Trim();
  DataTable dt2 = Conn.BindTable("SELECT * FROM " + strTable2 + " WHERE cellname='" + strcellname + "' ");  
  if (dt2.Rows.Count == 0)
  {
  Conn.ExecuteSql("insert into " + strTable2 + "(CellName,CellNameCN,SiteNo,SiteName,sitetype,LAC,CI,BSC,Status,siteclass) select EngName,ChineseName,workFreq,SiteName,sitetype,LAC,CI,BSC,Areaname,siteclass from " + strTable3 + " WHERE EngName='" + strcellname + "' and state=1");  
  }
   
  DataTable dt3 = Conn.BindTable("SELECT * FROM NormInfoTb WHERE IsAuto=1 and NormType =" + n + " and AnalyNorm= 1 and state=1");  
  if (dt3.Rows.Count != 0)
  {
  for (int j = 0; j < dt3.Rows.Count; j++)
  {
  strContent = dt3.Rows[j]["NormContent"].ToString().Replace("'", "''").Trim();  
  string strTargetDefault = dt3.Rows[j]["TargetDefault"].ToString().Replace("'", "''").Trim();  
   
  DataTable dtZd = Conn.BindTable("select 1 from sysobjects a inner join syscolumns b on a.id=b.id where a.id= object_id('" + strTable1 + "') and b.name='" + strContent + "'");
  if (dtZd.Rows.Count != 0)
  {
  strsqlavg = "SELECT avg(" + strContent + ") AS AvgNum FROM " + strTable1 + " WHERE normdatetime >= dateadd(hh,-10,getdate()) and normdatetime <= GetDate() and cellname='" + strcellname + "' ";
  DataTable dt4 = Conn.BindTable(strsqlavg);  
  string strnum = dt4.Rows[0][0].ToString().Replace("'", "''").Trim();  
  if (strnum != "")
  {
  strnum = float.Parse(strnum).ToString("f2");
  if (strTargetDefault == "True")
  {
  sql = "update " + strTable2 + " set " + strContent + "_Max=" + strnum + " WHERE cellname='" + strcellname + "'";  
  Conn.ExecuteSql(sql);
  }
  else