[英]i get an error with return value in my script sql of stored proc
我收到“A TOP 或 FETCH 子句包含无效值”这个错误
" Msg 1014, Niveau 15, État 1, Procédure dbo.sp_contacts_getcontacts, Ligne 24 [Ligne de départ du lot 0] TOP 或 FETCH 子句包含无效值。"
我想使用存储过程获取联系人,这是SP的代码
( @Id uniqueidentifier = NULL,
@role nvarchar(max) = NULL,
@IdCompany uniqueidentifier = NULL,
@Active bit = 0,
@Page int = NULL,
@PerPage int = NULL,
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON
-- Insert statements for procedure here
SELECT *
FROM [dbo].[Contacts]
LEFT JOIN [dbo].[Companies]
ON Contacts.[IdCompany] = Companies.[IdCompany]
WHERE
(@Id is null or @Id = [IdContact])
AND (@role is null or @role=contacts.[Role])
AND (@IdCompany is null or @IdCompany = [IdCompany])
AND (@Active = 0 or @Active = [Active])
ORDER BY [IdContact] OFFSET ((@Page - 1) * @PerPage) ROWS FETCH NEXT @PerPage ROWS ONLY
END
我可能误解了你的问题。 如果您想从该选择中获取结果,您将需要一个与插入到的 sproc 输出匹配的表变量。
DECLARE @someTable TABLE(
/* Whatever the output is of the sproc */
)
INSERT INTO @someTable
EXEC @return_value = dbo.nameOfYourSproc
您也可以尝试从结果中创建一个临时表
INSERT INTO #someTable
EXEC @return_value = dbo.nameOfYourSproc
不过,我的建议是将该 SPROC 转换为表值函数。
代码是正确的,我只是没有以这种方式插入页面和 perpage 的值,它显示错误“FETCH ...”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.