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

最新文章

  1. scala - multiple overloaded alternatives of method bar define default arguments
  2. LA 4329 Ping pong 树状数组
  3. java的三大框架(三)---Hibernate
  4. php SimpleXML 例子
  5. 知方可补不足~row_number,rank,dense_rank,ntile排名函数的用法
  6. iOS 采用个推时,未收到推送消息,测试DeviceToken无效
  7. 安卓App流量统计
  8. 【转】iOS超全开源框架、项目和学习资料汇总
  9. IOS CALayer(一)
  10. 自定义的 ListBoxItem 自适应ListBox的宽度
  11. Android IOS WebRTC 音视频开发总结(三七)-- 台湾help
  12. 分布式缓存BeIT Memcached简介
  13. 【转】Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
  14. setsockopt()使用方法()参数说明
  15. 终于了解了User-Agent的历史了
  16. NancyFX 第四章 Nancy快速上手 (使用Nancy模板)
  17. Error Code: 1044. Access denied for user 'root'@'%' to database
  18. 【Android Studio安装部署系列】十九、Android studio使用SVN
  19. Servlet学习1
  20. php开发工具,zendstudio13使用方法补丁

热门文章

  1. django 分组统计遇见的问题
  2. Flux架构与Redux简介
  3. fastJson 解析
  4. Docker_入门?只要这篇就够了!(纯干货适合0基础小白)
  5. IntelliJ IDEA 进行Maven项目创建build
  6. MapReduce----K-均值聚类算法
  7. DGA特征挖掘
  8. http --- 从输入URL到页面加载的过程发生了什么?
  9. The python programing language
  10. 机器学习(七) PCA与梯度上升法 (下)