查询分析器中: decalre @sqlstr varchar(200) select @sqlstr='select * into ##表 from 某表' --改用全局临时表,局部临时表在exec结束后,就被自动释放,当然后面的查询会错exec (@sqlstr) select * from ##表drop table ##表 --使用完成后删除
而VB中的.Private Sub Command1_Click() cc.Execute "select top 1 * into #lls from jc_bmxx" MsgBox 1 cc.Execute "select * from #lls" MsgBox 2 cc.Execute "select * from #lls" MsgBox 3 Set rst = cc.Execute("select * from #lls") '执行此句的时候,意思着生成临时表的过程结束,临时表被释放. MsgBox 4 cc.Execute "drop table #lls" ' ??这句话会出错,提示说“#lls 在系统目录中不存在 MsgBox 5 End Sub
to 邹健 for 问题2 第一次执行click时,提示‘#lls 不存在' 可第二次执行click ,在insert into 时 提示'#lls已存在' 所以我才把第一句改成cc.Execute "if object_id('tempdb.dbo.#lls') is not null drop table #lls select top 1 * into #lls from jc_bmxx" 则没有问题
decalre @sqlstr varchar(200) select @sqlstr='select * into ##表 from 某表' --改用全局临时表,局部临时表在exec结束后,就被自动释放,当然后面的查询会错exec (@sqlstr)
select * from ##表drop table ##表 --使用完成后删除
cc.Execute "select top 1 * into #lls from jc_bmxx"
MsgBox 1
cc.Execute "select * from #lls"
MsgBox 2
cc.Execute "select * from #lls"
MsgBox 3
Set rst = cc.Execute("select * from #lls") '执行此句的时候,意思着生成临时表的过程结束,临时表被释放.
MsgBox 4
cc.Execute "drop table #lls" ' ??这句话会出错,提示说“#lls 在系统目录中不存在
MsgBox 5
End Sub
for 问题2
第一次执行click时,提示‘#lls 不存在'
可第二次执行click ,在insert into 时 提示'#lls已存在'
所以我才把第一句改成cc.Execute "if object_id('tempdb.dbo.#lls') is not null drop table #lls select top 1 * into #lls from jc_bmxx" 则没有问题