ALTER Procedure [dbo].[sp1]
@ID int
As
IF(SELECT Grade FROM Tb1 WHERE ID=@ID)BETWEEN 15 AND 20
RETURN 'A'
else
RETURN 'B'
Declare @ID1 int
EXEC @ID1= sp1 '3';
Print convert(varchar(10) , @ID)
Go
答案 0 :(得分:0)
似乎你在编写查询时感到困惑,我希望以下查询可以帮助你
ALTER PROCEDURE [dbo].[sp1]
@ID int
As
BEGIN
SELECT CASE WHEN MARKS BETWEEN 15 AND 20 THEN
'A'
ELSE
'B'
END AS 'GRADE'
FROM [TABLE] WHERE ID=@ID
END
答案 1 :(得分:0)
你正试图获得存储过程的输出值,如果你想消耗整个输出,下面就是这样。
下面的是消耗整个sp输出的方法:
declare @test table
(id int)
create proc usp_test123
as
begin
select 1
end
insert into @test
exec usp_test123
select * from @test
否则,您可以使用输出返回和conusme特定值
create proc usp_test1234
(
@id int out
)
as
begin
select @id=1
end
declare @id int
exec usp_test1234
@id =@id output
select @id
答案 2 :(得分:0)
不确定您要做什么,但这是一种在程序中使用输出参数获取A / B等级然后打印它的方法:
ALTER Procedure [dbo].[sp1]
@ID int,
@Grade char(1) output
As
IF (exists (SELECT 1 FROM Tb1 WHERE ID=@ID and Grade BETWEEN 15 AND 20))
set @Grade = 'A'
else
set @Grade = 'B'
go
Declare @ID1 int, @Grade char(1)
set @ID1 = 3
EXEC sp1 @ID1, @Grade output
Print @Grade