str:=''<br>+'declare @T table'<br>+'('<br>+' yf tinyint,'<br>+' nd1 money,'<br>+' nd2 money'<br>+');'<br>+'declare'<br>+' @nd int,'<br>+' @yf int,'<br>+' @i tinyint,'<br>+' @Cdate datetime,'<br>+' @Cdate1 datetime,'<br>+' @yfksrq tinyint,'<br>+' @yfjsrq tinyint;'<br>+'set @Cdate='+quotedstr(cxDateEdit1.Text)+';'<br>+'set @nd=year(@Cdate)-1;'<br>+'set @yf=month(getdate());'<br>+'select @yfksrq=yfksrq,@yfjsrq=yfjsrq from xtxxb;'<br>+'if (month(getdate())=12 and day(getdate())>@yfksrq)'<br>+' set @nd=year(getdate());'<br>+'set @i=1;'<br>+'while @i<=12 '<br>+'begin'<br>+' set @Cdate1=dateadd(month,-1,cast(cast(year(dateadd(year,-1,@Cdate)) as char(4))+'+quotedstr('-')+'+cast(@i as varchar(2))+'+quotedstr('-')+'+cast(@yfksrq as varchar(2)) as datetime));'<br>+' insert @T (yf) values(@i);'<br>+' update @T set nd1=je from (select @i as yf1,sum(hkje) as je from hkzb b where '<br><br> +' b.hkrq>=cast(year(@Cdate1) as char(4))+'+quotedstr('-')+'+cast(month(@cdate1) as varchar(2))+'+quotedstr('-')+'+cast(day(@cdate1) as varchar(2))'<br> +' and b.hkrq<=cast(year(dateadd(year,-1,@Cdate)) as char(4))+'+quotedstr('-')+'+cast(@i as varchar(2))+'+quotedstr('-')+'+cast(@yfjsrq as varchar(2))'<br><br> +fs+qx+tj+') a where a.yf1=yf;'<br>+' set @i=@i+1;'<br>+'end;'<br><br>+'set @i=1;'<br>+'if year(getdate())>year(@Cdate) set @yf=12;'<br>+'while @i<=@yf '<br>+'begin'<br>+' set @Cdate1=dateadd(month,-1,cast(cast(year(@Cdate) as char(4))+'+quotedstr('-')+'+cast(@i as varchar(2))+'+quotedstr('-')+'+cast(@yfksrq as varchar(2)) as datetime));'<br>+' update @T set nd2=a.fhsl from (select @i as yf1,sum(b.hkje) as fhsl'<br>+' from hkzb b'<br>+' where '<br><br> +' b.hkrq>=cast(year(@Cdate1) as char(4))+'+quotedstr('-')+'+cast(month(@cdate1) as varchar(2))+'+quotedstr('-')+'+cast(day(@cdate1) as varchar(2))'<br> +' and b.hkrq<=cast(year(@Cdate) as char(4))+'+quotedstr('-')+'+cast(@i as varchar(2))+'+quotedstr('-')+'+cast(@yfjsrq as varchar(2))'<br>+fs+qx+tj+' ) a'<br>+' where a.yf1=yf;'<br>+' set @i=@i+1;'<br>+'end;'<br>+' insert @T (yf,nd1,nd2) values(13,@nd,@nd+1);'<br>+'update @T set nd1=0 where nd1 is null;'<br>+'update @T set nd2=0 where nd2 is null and yf<=@yf;'<br>+'select * from @T;';<br>with LineCDS do<br>begin<br> Close;<br> CommandText:=str;<br> Open;<br>end;<br>看看代码吧,执行Open就出这个错误了。