我想要做的是,我有一个design_sheet作为数据库中的表和多个表格格式
'sb16im2yr_c',COUNTYID, 'Y',YEAR, '_',方法 '_ 9653_20MY_out'
在design_sheet中,它为每行提供了COUNTYID,YEAR,METHOD
所以我尝试使用它来为每行提供输入表
set @COUNTYDATA = concat('sb16im2yr_c',@COUNTYID,'y',@YEAR,'_',@METHOD,'_9653_20MY_out')
然后使用
set @str = concat(BALA)
帮助我将每个表中的数据插入到汇总表'INSERT INTO ',@SUMMARY,'
。`',@ SUMMARY_TB
总体代码在这里
SET @n = 0;
SET @COUNTYID = (Select countyID From `sb16im2yr_summary`.`design_sheet`
where year=@YEAR limit @n,@n+1);
select @COUNTYID;
SET @METHOD = (Select TMD_HPMS From `sb16im2yr_summary`.`design_sheet`
where year=@YEAR limit @n,@n+1);
SET @EXT = (Select IM frequency From `sb16im2yr_summary`.`design_sheet`
where year=@YEAR limit @n,@n+1);
set @COUNTYDATA = concat('sb16im2yr_c',@COUNTYID,'y',@YEAR,'_',@METHOD,'_9653_20MY_out');
set @str = concat('INSERT INTO `',@SUMMARY,'`.`',@SUMMARY_TB,'`
(`MOVESRunName`, `MOVESRunID`, `outputTimePeriod`, `timeUnits`, `distanceUnits`,
`massUnits`, `energyUnits`, `runSpecFileName`, `runSpecDescription`, `runSpecFileDateTime`,
`runDateTime`, `scale`, `minutesDuration`, `defaultDatabaseUsed`, `masterVersion`,
`masterComputerID`, `masterIDNumber`, `domain`, `domainCountyID`, `domainCountyName`,
`domainDatabaseServer`, `domainDatabaseName`, `expectedDONEFiles`, `retrievedDONEFiles`,
`models`)
SELECT "',@COUNTYDATA,'",
`MOVESRunID`, `outputTimePeriod`, `timeUnits`, `distanceUnits`, `massUnits`,
`energyUnits`, `runSpecFileName`, `runSpecDescription`, `runSpecFileDateTime`,
`runDateTime`, `scale`, `minutesDuration`, `defaultDatabaseUsed`, `masterVersion`,
`masterComputerID`, `masterIDNumber`, `domain`, `domainCountyID`, `domainCountyName`,
`domainDatabaseServer`, `domainDatabaseName`, `expectedDONEFiles`, `retrievedDONEFiles`,
`models`
FROM `',@COUNTYDATA,'`.`movesrun`;');
PREPARE stmt from @str;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;