sql insert select from 语句

2009-09-25

此语句写在ERP项目中。

 public void   dbdck(string dbdckdh)

        {

            string yyyyMMdd;

            string ckdh;

            string insertSql;

            //获取当前的日期

             yyyyMMdd=(DateTime .Now ).ToString ("yyyyMMdd").Substring(0,6);

             //获取出库单号   

            ckdh = comm.GetDjbh("ckd",yyyyMMdd);

            //根据单号,把数据插入到出库单1

             insertSql = " insert into ckd1 (ckd1_ckdh,ckd1_zdrq,ckd1_ckbh,ckd1_dwbh,ckd1_zdry,ckd1_rybh,ckd1_jzbz,ckd1_ywbz,ckd1_hdbz,ckd1_dbdh,ckd1_pddh,ckd1_zxdh) ";

             insertSql += " select '" + ckdh + "' ,'" + DateTime.Now.ToString("yyyyMMdd") + "',dbd1_ycck,' ',dbd1_zdry , dbd1_rybh ,'Y' , 'qtck', ' ' ,' ',' ','' ";

             insertSql += " from dbd1 where dbd1_dbdh ='"+dbdckdh+"' ";

            //根据单号,把数据插入到出库单2

             insertSql += " insert into ckd2( ckd2_ckdh,ckd2_flbh,ckd2_wlbh,ckd2_cksl,ckd2_dj ) ";

             insertSql += " select '"+ckdh +"',dbd2_flbh,dbd2_wlbh,dbd2_dbsl,'') ";

             insertSql += " from dbd2 dbd1_dbdh='"+ dbdckdh+"' ";



             SqlHelper.SqlHelper.ExecuteDataset(insertSql);

             comm.SetDjbh("ckd",yyyyMMdd,Convert.ToInt32(ckdh.Substring(6,6)));

            //调用出库单记账

             comm.DeliverKeepAccount(ckdh,"记账");

        }

 

你可能感兴趣的:(select)