<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'更多推荐
发布评论