ADODB.Recordset与sql语句的结合问题
dim rs as ADODB.Recordset
set rs=db.execute("select * from 進貨單20051") 这个语句执行后当然可以有相应的记录
问题是如果复杂一些的.(20051表示2005年1月)下面的语句在sql的查询分析器里
declare @sql varchar(8000)
set @sql='select * from '
select @sql=@sql+name+' union all select * from ' from sysobjects where name like '進貨單%' and xtype='U' order by name
set @sql=left(@sql,len(@sql)-24)
print @sql
exec(@sql)
将会得到一下结果
select * from 進貨單200012 union all select * from 進貨單20011 union all select * from 進貨單20012 union all select * from 進貨單200212 union all select * from 進貨單200310 union all select * from 進貨單20033 union all select * from 進貨單20038 union all select * from 進貨單20039 union all select * from 進貨單20041 union all select * from 進貨單200410 union all select * from 進貨單200411 union all select * from 進貨單200412 union all select * from 進貨單20042 union all select * from 進貨單20043 union all select * from 進貨單20044 union all select * from 進貨單20045 union all select * from 進貨單20046 union all select * from 進貨單20047 union all select * from 進貨單20048 union all select * from 進貨單20049 union all select * from 進貨單20051 union all select * from 進貨單20052 union all select * from 進貨單20053 union all select * from 進貨單20054 union all select * from 進貨單20055 union all select * from 進貨單20073 union all select * from 進貨單20083 union all select * from 進貨單資会把所有不同年份的进货单连接,在sql的查询分析器里把相应的记录也会出现,问题是,如果是在开发应用程序里面,比如vb,定义变量
dim find  as string
dim recfind as adodb.recordset
find ="declare @sql varchar(8000) set @sql='select * from ' select @sql=@sql+name+' where 貨品ID = 197 union all select * from ' from sysobjects where name like '進貨單2005%' and xtype='U' order by name set @sql=left(@sql,len(@sql)-24)exec(@sql) "
set refind = db.execute(find)却是什么记录也没有,而且也沒有error出現,到底应该如何做呢???他不像dim rs as ADODB.Recordset
set rs=db.execute("select * from 進貨單200501") 可以返回记录啊,想问问谁能解决呢?