存储过程和 .NET:临时表上的 SELECT INTO:抑制结果

发布于 2024-07-29 11:23:39 字数 213 浏览 4 评论 0原文

我正在从 ADO.NET 访问存储过程。 存储过程最终应该返回一个结果集。

为了计算此结果,需要使用 SELECT INTO 语句填充临时表。

问题是 SELECT INTO 语句的结果也作为结果集返回到 .NET。

这能压制住吗? 或者我不应该使用 SELECT INTO,而是使用 CREATE TABLE,然后使用 INSERT 语句?

I'm accessing a stored procedure from ADO.NET.
The stored procedure should eventually returns a single result set.

To compute this result, a temporary table is filled with a SELECT INTO statement.

The problem is that the result of the SELECT INTO statement is also returned as a result set to .NET.

Can this be suppressed? Or should I not use SELECT INTO, but CREATE TABLE followed by an INSERT statement?

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

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

发布评论

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

评论(1

若相惜即相离 2024-08-05 11:23:39

我建议避免 SELECT INTO 因为它将推断您的列名称/类型,并且如果您的源查询有任何复杂性(例如 CASE 语句),这可能会产生意外的结果。

如果我需要保存所描述的值,我总是创建一个表变量或临时表。

如果您使用 CREATE TABLE #TableName () (或 DECLARE @tableName TABLE ())然后使用 INSERT 那么您将不会获得返回的额外结果集。

I would suggest avoiding SELECT INTO as it's going to infer your column names/types, and if your source query is in any way complex (such as CASE statements) this can produce unexpected results.

I always create either a table variable or a temp table if I need to hold values as described.

If you use CREATE TABLE #TableName () (or DECLARE @tableName TABLE ()) then use INSERT then you won't get the extra result set returned.

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