为什么sp

编程入门 行业动态 更新时间:2024-10-27 04:29:34
<span>为什么sp_executesql在直接SP调用时不返回结果?(Why sp_executesql doesn't return results while direct SP call does?)

这令人困惑。 对于存储过程的此声明:

CREATE PROCEDURE dbo.JobGet @jobGuid uniqueidentifier = NULL,

该行返回结果:

exec dbo.JobGet @jobGuid ='BDEA1E43-9EC7-42B0-A386-903FE1749FF7'

这个不是:

exec sp_executesql N'dbo.JobGet',N'@jobGuid uniqueidentifier',@jobGuid='BDEA1E43-9EC7-42B0-A386-903FE1749FF7'

有人可以解释为什么吗

This is confusing. For this declaration of the stored procedure:

CREATE PROCEDURE dbo.JobGet @jobGuid uniqueidentifier = NULL,

This line returns results:

exec dbo.JobGet @jobGuid ='BDEA1E43-9EC7-42B0-A386-903FE1749FF7'

And this one does not:

exec sp_executesql N'dbo.JobGet',N'@jobGuid uniqueidentifier',@jobGuid='BDEA1E43-9EC7-42B0-A386-903FE1749FF7'

Can anyone explain why?

最满意答案

调用SP时,需要将@jobGuid添加为参数。 没有它,参数将具有默认值NULL 。

exec sp_executesql N'dbo.JobGet @jobGuid', N'@jobGuid uniqueidentifier', @jobGuid='BDEA1E43-9EC7-42B0-A386-903FE1749FF7'

You need to add @jobGuid as a parameter when you call the SP. Without it the parameter will have the default value NULL.

exec sp_executesql N'dbo.JobGet @jobGuid', N'@jobGuid uniqueidentifier', @jobGuid='BDEA1E43-9EC7-42B0-A386-903FE1749FF7'

更多推荐

本文发布于:2023-08-07 14:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464724.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:sp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!