2014-06-24 217 views
0

我有这样一个存储过程:获得在SQL Server多个返回值

ALTER procedure [dbo].[MobileDevice] 
@platesourcecnt integer, 
@plateCategory integer 
as 
begin 
declare @SplateSourcecount integer, 
@SplateCategory integer, 
@Splatecode integer 


select @SplateSourcecount= count(ps.PSID)from PlateSource_tbl ps 
if @SplateSourcecount <> @platesourcecnt 
begin 
select PSID,PS from PlateSource_tbl where Deleted=0 
end 
else 
begin 
return 1 

end 

Select @SplateCategory=COUNT(pcat.PCID) from PlateCategory_tbl pcat 
if @SplateCategory <> @plateCategory 
begin 
select PCID,PC,PSID from PlateCategory_tbl where Deleted=0 
end 
else 
begin 
return 2 
end 

这里我platesource_tblcount13,如果我通过价值@platesourcecnt =13然后我得到返回值1但那次我的第二个选择查询不起作用。
如果我将除13之外的其他参数传递给@platesourcecnt,那么两者都可以工作。
我的存储过程有什么问题?
我可以在一个存储过程中获得多个返回值吗?

+0

为什么要返回,U需要它? – Azar

+0

我想查询一下wethar先查询返回值还是不行? – user3252014

+0

然后使用我给出的变量解决方案 – Azar

回答

1

不,你不能返回两次,一个回报将带你出去,

而是使用选择1退货1,选择2回2

或者宣布两个变量@ RETURN1,@ RETURN2 在PROC选择@ RETURN1 'RETURN1' 末,@ RETURN2 'RETURN2'

0

尝试thiss PROC

ALTER procedure [dbo].[MobileDevice] 
@platesourcecnt integer, 
@plateCategory integer 
as 

if (select count(ps.PSID)from PlateSource_tbl ps)<> @platesourcecnt 
select PSID,PS from PlateSource_tbl where Deleted=0 
else 
raiserror('1st return',16,1) 

if (Select COUNT(pcat.PCID) from PlateCategory_tbl pcat)<> @plateCategory 
select PCID,PC,PSID from PlateCategory_tbl where Deleted=0 
else 
raiserror('2nd return',16,1) 
+0

你的意思是raiserror? – user3252014

+0

Jst知道if语句是否返回值 – Azar

+0

而不是我们可以用select select? – user3252014