日期:2014-05-17 浏览次数:20634 次
SET @sql_word= 'insert into '+@ResultTable +'
select distinct EXITSTATION,11,exitdate,RECORDTYPE,vehicleclass,totaltoll
from '+@BaseTable+'
where EXITSTATION = '+@Station+'
GROUP BY exitdate,EXITSTATION,RECORDTYPE,vehicleclass,totaltoll
order by EXITSTATION,exitdate,RECORDTYPE,vehicleclass,totaltoll'
print(@sql_word)
exec(@sql_word)
就这样改。再试试
if @Station <>''
begin
SET @sql_word= 'insert into '+@ResultTable +'
select distinct EXITSTATION,11,exitdate,RECORDTYPE,vehicleclass,totaltoll
from '+@BaseTable+'
where EXITSTATION = '+@Station+'
GROUP BY exitdate,EXITSTATION,RECORDTYPE,vehicleclass,totaltoll
order by EXITSTATION,exitdate,RECORDTYPE,vehicleclass,totaltoll'
end
SET @sql_word= 'insert into '+@ResultTable
+' select distinct EXITSTATION,11,exitdate,RECORDTYPE,vehicleclass,totaltoll '
+' from '+@BaseTable
+' where 1=1 '+case when @Station<>'' then ' and EXITSTATION='''+@Station+''' ' else '' end