Excel VBA - exec script to drop temp table

I want to drop a # temp table when running then macro, is it correct to use: tempdb..sysobjects The script is: sScript = sScript + "IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE xtype = 'U' AND name like '#vl_enrolledByDate%') " & vbCrLf sScript = sScript + "BEGIN " & vbCrLf sScript = sScript + "DROP TABLE #vl_enrolledByDate " & vbCrLf sScript = sScript + "End " & vbCrLf iVal = execute_sql_command(sServer, sDatabase, sScript) The sServer eg. is SQLPROD01 and sDatabase eg. is scratchdb, but I read that #tables are stored in tempdb database, is this the reason why the table does not exist? So when I run the macro it returns the following error message: Run-time error '-2147217865 (80040e37)': Cannot drop the table '#vl_enrolledByDate', because it does not exist in the system cataglog. But if I create a non # table and just use (SELECT * FROM sysobjects WHERE xtype = 'U' AND name like 'vl_enrolledByDate%') it's fine.

以上就是Excel VBA - exec script to drop temp table的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » excel

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准