存储过程和 .NET:临时表上的 SELECT INTO:抑制结果
我正在从 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议避免 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.