https://stackoverflow.com/questions/10417126/dynamically-named-temp-table-returns-invalid-object-name-when-referenced-in-st

You are doing it wrong!

Try:

exec(@SQL)

instead of:

EXECUTE sp_executesql @SQL

To use sp_executesql the variable must be inside @SessionID the quotes and it must be provided has input parameter. Check this for a full example!


You've to be aware that Dynamic SQL is a good port for SQL injections!

https://stackoverflow.com/questions/11506314/invalid-object-name-temp-in-dynamic-sql-and-array-of-field-names

The temp table is out of scope after exec is done.'exec' or 'sp_executesql' are run in thier own scope.

Thus anything created like temp tables and variables are destroyed or out of scope as soon as execution is over .Think these like stored proc.

To fix the issue.Create the temp table in main code.. then insert into it using dynmic sql and then read it in main code.

http://www.sommarskog.se/dynamic_sql.html#sp_executesqlong

sp_executesql invalid object name的更多相关文章

  1. Recompile the invalid object for oracle.

    1. How does the invalid object come? The Oracle database will invalidate objects if a dependent obje ...

  2. Invalid object name ‘sys.configurations’. (Microsoft SQL Server, Error: 208)

    http://blogs.msdn.com/b/ramaprasanna/archive/2009/09/16/invalid-object-name-sys-configurations-micro ...

  3. MacTex XeLaTex xdvipdfmx:fatal: pdf_ref_obj(): passed invalid object. 报错的解决方法

    在使用MacTex配合TexStudio编译beamer的时候,爆出如下错误, xdvipdfmx:fatal: pdf_ref_obj(): passed invalid object. 结果尝试其 ...

  4. Oracle EBS 重新编译无效对象 invalid object

    1.  查看数据库中的无效对象      check oracle object      SQL> select count(*) from dba_objects where status= ...

  5. sql - Invalid object name 'dbo.in$'

    这是我从excel导入的表,用查询的时候,不加前面部分的'dbo',能查出来,好像是owner的原因吧.

  6. oracle impdp ORA-02304 invalid object identifier literal

    reference: https://webgeest.blogspot.com/2015/07/ora-39083-ora-02304-on-impdp-datapump.html     解决方法 ...

  7. 讨论贴:在sp_executesql 中生成的临时表的可见性

    首先创建数据表 IF object_id('TestTable') IS NOT NULL DROP TABLE TestTable GO ,),Info )) GO INSERT TestTable ...

  8. EXEC sp_executesql with multiple parameters

    传递多个参数 https://stackoverflow.com/questions/28481189/exec-sp-executesql-with-multiple-parameters http ...

  9. [terry笔记]IMPDP报错ORA-39083 Object type TYPE failed to create ORA-02304

    今天在使用impdp导入的时候(同一数据库中转换schema),遇到了 ORA-39083: Object type TYPE failed to create with error: ORA-023 ...

随机推荐

  1. IE模式下EasyUI Combobox无效问题

    近期开发过程中遇到IE浏览器Combobox无法正常加载问题. 经过一番百度说IE渲染过快导致页面渲染完了easyUI Combobox还没有加载.设置延迟加载后依旧无效. 后将input标签的Cla ...

  2. POJ-1511 Invitation Cards 往返最短路 邻接表 大量数据下的处理方法

    题目链接:https://cn.vjudge.net/problem/POJ-1511 题意 给出一个图 求从节点1到任意节点的往返路程和 思路 没有考虑稀疏图,上手给了一个Dijsktra(按紫书上 ...

  3. 紫书 习题 8-21 UVa 1621 (问题分析方法)

    知道是构造法但是想了挺久没有什么思路. 然后去找博客竟然只有一篇!!https://blog.csdn.net/no_name233/article/details/51909300 然后博客里面又说 ...

  4. 实现图像剪裁 jquery.Jcrop

       配合 jquery.Jcrop 实现上传图片进行剪裁保存功能    <script src="js/jquery.min.js"></script> ...

  5. 用java实现螺旋数组

    接收数组的行数和列数,返回正序和倒序的螺旋数组 package cn.baokx; public class Test { public static void main(String[] args) ...

  6. emmet教程

    https://www.zfanw.com/blog/zencoding-vim-tutorial-chinese.html https://www.zfanw.com/blog/zencoding- ...

  7. html5播放m3u8视频,web端看直播

    https://github.com/jiqing9006/hLive <!DOCTYPE html> <html> <head> <meta charset ...

  8. Xshell高级后门完整分析报告

    Xshell高级后门完整分析报告 from:https://security.tencent.com/index.php/blog/msg/120 1. 前言 近日,Xshell官方发布公告称其软件中 ...

  9. matplotlib 可视化 —— 绘制常见图形

    0. 饼状图 plt.pie():Python数据可视化:饼状图 1. 三角形 描点连线,起点和终点相同 triangle1 = ((0, sqrt(3)/2), (1, 3*sqrt(3)/2), ...

  10. jquery操作select的各种方法

    在工作中,有时候会遇到给select组件添加一些事件,前两天发表了一篇文章,<用jquery给select加选中事件>大致阐述了简单的jq操作select的方法,但是为了详细的介绍一下se ...