我有这个存储过程,它不返回任何值我运行EXEC命令
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GClient]
@CLIENT_CODE INT = NULL output,
@CLIENT_NAME VARCHAR = 50 output,
@CATEGORY VARCHAR = 50 output,
@ATC VARCHAR = 50 output
AS
BEGIN
SELECT
*
FROM
dbo.CLIENT
WHERE
CLIENT_CODE = @CLIENT_CODE OR
CLIENT_NAME = @CLIENT_NAME OR
CATEGORY = @CATEGORY OR
ATC = @ATC;
END
我这样执行:
DECLARE @client_name varchar(50)
EXEC GCLIENT @client_name='rillera general merchandise'
表上有一个记录有该值,我不知道为什么它根本不返回任何记录。
答案 0 :(得分:0)
使用输入参数修改过程并将列分配给输出参数。
ALTER PROCEDURE [dbo].[GClient]
@client_name varchar(50)
@CLIENT_CODE INT output,
@CLIENT_NAME VARCHAR(50) output,
@CATEGORY VARCHAR(50) output,
@ATC VARCHAR(50) output
AS
BEGIN
SELECT
@CLIENT_CODE = CLIENT_CODE,
@CLIENT_NAME=CLIENT_NAME,
@CATEGORY = CATEGORY,
@ATC = ATC
FROM
dbo.CLIENT
WHERE
client_name =@client_name
END
此外,您的执行步骤是错误的,您需要声明输出参数并使用exec调用它们。例如。
DECLARE @CLIENT_CODE varchar(50)
DECLARE @CLIENT_NAME varchar(50)
DECLARE @CATEGORY varchar(50)
DECLARE @ATC varchar(50)
EXEC GCLIENT 'rillera general merchandise', @CLIENT_CODE OUTPUT,
@CLIENT_NAME OUTPUT, @CATEGORY OUTPUT, @ATC OUTPUT
答案 1 :(得分:0)
你可以删除掉put子句,因为你有表中指定的输出列并给出一个输入参数
Create PROCEDURE USP_GClient
@CLIENT_NAME varchar(50)
AS
BEGIN
SELECT
CLIENT_CODE
,CLIENT_NAME
,CATEGORY
,ATC
FROM
DBO.CLIENT
WHERE
CLIENT_NAME=@CLIENT_NAME
END
并执行proc
EXEC USP_GClient @CLIENT_NAME