从 CLR 存储过程访问 TSQL 创建的#temp 表。 是否可以?

发布于 2024-07-16 07:15:07 字数 381 浏览 5 评论 0原文

  1. 我有一个 TSQL 存储过程 tsql__sp__A,它执行两件事:

(a) 创建一个临时表 #tempTable,其中包含来自复杂 SELECT 查询的 SELECT 数据。

(b) 为对行参数进行计算的每一行调用 CLR 管理的存储过程 clr__sp__B

问题:是否可以使用相同的连接上下文从 CLR 过程 clr__sp__B 访问 #tempTable? (不,我不想在托管过程中移动或创建另一个#tempTable

谢谢。

  1. I have a TSQL Stored Procedure tsql__sp__A which does two things:

(a) Creates a temp table #tempTable that has SELECT data from a complex SELECT query.

(b) Calls a CLR managed Stored Procedure clr__sp__B for each row that does computation on row parameters.

Question: Is it possible to access #tempTable from CLR procedure clr__sp__B using the same connection context? (No, I don't want to move or create another #tempTable inside managed procedure)

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱娆 2024-07-23 07:15:07

谢谢日本央行。

但是我发现,当您使用“contextconnections=true”时,它会打开所有 SET

阅读 Bol 文章

//上下文连接允许您在与代码最初被调用的上下文相同的上下文中执行 SQL 语句//

using (SqlConnection connection = new SqlConnection("context connection=true"))
{
    connection.Open();
    // access #temp table
}

Thank you Boj.

However I found that when you use with a "context connections=true" it opens up all the SET

Read Bol Article

//The context connection lets you execute SQL statements in the same context that your code was invoked in the first place//

using (SqlConnection connection = new SqlConnection("context connection=true"))
{
    connection.Open();
    // access #temp table
}
夜空下最亮的亮点 2024-07-23 07:15:07

我们可以在 SQL 中定义两种类型的临时表。

  • local
  • global

关于本地临时表:

当表前面有单个“#”符号时,它被定义为本地临时表,其范围仅限于创建它的会话。

关于全局临时表:

与本地临时表相比,全局临时表在整个实例中都是可见的。

因此,您可能应该尝试使用“##”来创建全局临时表。 (如果“连接上下文”和“会话”之间存在差异)

We can define two types of temp tables in SQL.

  • local
  • global

About local temp tables:

When table is preceded by single ‘#’ sign, it is defined as local temporary table and its scope is limited to session in which it is created.

And about global temp tables:

In contrast of local temporary tables, global temporary tables are visible across entire instance.

So may you should try using "##" to create a global temp table. (If there is a difference between "connection context" and "session")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文