//事务的处理
try{
ADOQuery1-> Close();
ADOQuery1-> SQL-> Clear();
//开始事务
ADOQuery1-> SQL-> Add( "BEGIN TRAN ");
//更新temp_price表的intime字段
ADOQuery1->SQL->Add("update zzcz.dbo.temp_price set intime="+intimenow);
//插入到sto_price表中
ADOQuery1->SQL->Add("insert into zzcz.dbo.sto_price select * from zzcz.dbo.temp_price");
//创建和cg30_p_p_price相似结构的表
ADOQuery1->SQL->Add("create table zzcz.dbo.zz_price(start_date char(8) not null default '',stop_date char(8) not null default'',train_no char(12) not null,from_station_name char(10) not null default'郑州',to_station_name char(10) not null,ticket_type int not null default 0,belong_line tinyint not null default 0,seat_type_code char(1) not null default'',bed_level char(1) not null default'',price smallint not null,service_cost smallint not null default 0,origin char(2) not null default'',replicate_range int)");
//插入zz_price表中相应的数据
ADOQuery1->SQL->Add("insert into zzcz.dbo.zz_price(train_no,to_station_name,seat_type_code,bed_level,price) select train_no,station_name,substring(seat_type_code,1,1),substring(seat_type_code,2,1),convert(smallint,ticket_price) from zzcz.dbo.sto_price where intime="+intimenow);
//删除cg30_p_price表中from_station_name为郑州的数据
ADOQuery1->SQL->Add("delete from zzcz.dbo.cg30_p_p_price where from_station_name='郑州'");
//把zz_price中的数据插入到cg30_p_p_price中去
ADOQuery1->SQL->Add("insert into zzcz.dbo.cg30_p_p_price select * from zzcz.dbo.zz_price");
//删除临时表temp_price
ADOQuery1->SQL->Add("drop table zzcz.dbo.temp_price");
//删除临时表zz_price
ADOQuery1->SQL->Add("drop table zzcz.dbo.zz_price");
//删除表sto_price中的旧数据
ADOQuery1->SQL->Add("delete from zzcz.dbo.sto_price where datediff(ss,substring(intime,1,4)+'-'+substring(intime,5,2)+'-'+substring(intime,7,2)+' '+substring(intime,9,2)+':'+substring(intime,11,2)+':'+substring(intime,13,2),'"+datetime+"')>0");
//提交事务
ADOQuery1-> SQL-> Add( "COMMIT TRAN ");
//如果出错回滚事务
ADOQuery1-> SQL-> Add("IF @@error <> 0 ROLLBACK TRAN");
ADOQuery1-> ExecSQL();
}catch(Exception &E)
{
ShowMessage(E.Message);
}
//使用的ado组件。