将多个查询的结果集存储在内存中?

发布于 2024-10-18 08:24:07 字数 241 浏览 2 评论 0原文

我认为 CTE 非常适合我的存储过程,直到我发现它们只能在一个查询中引用(即紧随 CTE 之后的查询)。现在看来它们毫无意义。

我正在寻找一种方法来执行查询,将该结果集存储在内存中(而不是像临时表或表变量一样存储在磁盘上),然后在多个 SELECT/INSERT/UPDATE 语句中的存储过程中引用它。就像临时视图,或者范围更长的 CTE。但这在 SQL Server 中似乎根本不存在!有人有解决办法吗?这对于 CTE 功能来说是不是显得相当短视?

I thought CTEs were perfect for my stored procedure, until I found out they can only be referenced in ONE query (ie the query immediately following the CTE). They now seem fairly pointless.

I'm looking for a way to perform a query, store that result set in memory (not on disk like a temp table or table variable), and then reference it within a stored procedure in multiple SELECT/INSERT/UPDATE statements. Just like a temporary view, or a CTE with a longer scope. But that doesn't seem to exist at all in SQL Server! Does anyone have a solution? Doesn't this seem rather short-sighted on behalf of the CTE functionality?

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

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

发布评论

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

评论(1

征棹 2024-10-25 08:24:07

我同意这些评论。我也不确切知道如何完成以下操作,但我认为它会起作用。话虽如此:让您的查询生成 XML 输出,将该输出存储在 XML 变量中,然后使用 xquery 引用它并从中提取数据以用于过程的其余部分。 (但同样,我完全不确定您是否可以编写“SELECT @XML = ...”查询。也许是 OPENXML,或者类似的东西?)

I agree with the comments. I also don't know precisely how the following would be done, but I think it would work. With that said: have your query generate XML output, store that output in an XML variable, and then use xquery to reference and extract data from it for the rest of the procedure. (But again, I'm not at all sure you can write a "SELECT @XML = ..." query. Maybe OPENXML, or something like that?)

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