SQL Server 2005 - 存储 RowSet 的变量的数据类型
在我正在工作的典型存储过程中,有使用相同查询的各种检查,如下所示。
SELECT ... FROM Projects WHERE ProjectId IN (SELECT ProjectId FROM Tasks)
我想用变量
替换查询(SELECT ProjectId FROM Tasks)
,但对它必须是什么数据类型
感到困惑。 你知道吗?缓存这个结果也是有害的,或者是否有更简单的方法来做到这一点。
In a typical stored procedure i am working there are various checks with the same query as below.
SELECT ... FROM Projects WHERE ProjectId IN (SELECT ProjectId FROM Tasks)
i would like to replace the query (SELECT ProjectId FROM Tasks)
with a variable
but am confused as to what datatype
it has to be. Do you know? also caching this result is detrimental or is there easier way to doing this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以创建表类型变量并多次使用它,如下所示:
- 它不是用变量替换查询,但它使子查询结果更可重用
但是
虽然 某些情况下这可能会降低查询的性能
You may cteate table typed variable and use it multiple times, like that:
Althought - it is not replacement of query by variable, it is make more reusable the subquery results
But
under certain conditions this may degrade your queries' performance