0

I have a stored procedure like this:

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

end

Here my platesource_tbl count is 13, if I pass value to @platesourcecnt =13 then I am getting return value 1 but that time my second select query is not working.
If I pass other parameter than 13 to @platesourcecnt then getting both working.
What is wrong with my stored procedure?
Can I get multiple return value in one stored procedure?

6
  • Why you want to return , u require it for? Commented Jun 24, 2014 at 10:29
  • i want to check wethar first query returned value or not? Commented Jun 24, 2014 at 10:31
  • then use the variable solution i have given below Commented Jun 24, 2014 at 10:32
  • yes,i used,now i am getting expected out put. Commented Jun 24, 2014 at 10:33
  • i can optimize this stored procedure better than this methode? Commented Jun 24, 2014 at 10:34

2 Answers 2

1

No you cannot return two times , one return will take you out,

Instead use Select 1 for return 1 , Select 2 for return 2

Or Declare two variables @return1, @return2 At the end of Proc Select @return1 'return1',@return2 'return2'

Sign up to request clarification or add additional context in comments.

Comments

0

Try 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) 

2 Comments

Jst to know whether if statement returned values or not
U can but this is like a message which is helpful for you as you said that you want to know whether it is returning rows in first and second if statements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.