你的错误是:if (1=2)
{
  int i;
}i=2; <<====你在写程序也这样用吗?它是有生命周期的。

解决方案 »

  1.   

    查询分析器中:
    decalre @sqlstr varchar(200) select @sqlstr='select * into ##表 from 某表'  --改用全局临时表,局部临时表在exec结束后,就被自动释放,当然后面的查询会错exec (@sqlstr) 
    select * from ##表drop table ##表  --使用完成后删除
      

  2.   

    而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
      

  3.   

    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" 则没有问题
      

  4.   

    如果用全局表,因为要适应多用户并发,必须要标识每个连接,为每个连接建立不同的临时表,标识不同连接是否用@@SPID就可以了?