Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored Procedure - expecting 2 input parameters - WHY?? 1

Status
Not open for further replies.

eb24

Programmer
Dec 17, 2003
240
US
I have a stored procedure where I would like to input ONLY 1 parameter, but when I execute the SP, it expects 2 parameters! I don't know why! I enter the CheckNum fine, but then it expects me to enter myRowCount as well, but isn't it an OUTPUT paramater:

Code:
CREATE PROCEDURE dbo.spGetChecksByCheckNum
	(
		@CheckNum varchar(50), 
		@myRowCount int output
	)

AS

SELECT CheckID, Vendor, Invoice, Amt, CheckNum, CheckAmt, Status FROM tblChecks INNER JOIN tblStatus ON tblChecks.StatusID = tblStatus.StatusID WHERE CheckNum = @CheckNum;

/* @@ROWCOUNT returns the number of rows that are affected by the last statement. */ 
SELECT @myRowCount=@@ROWCOUNT
Hopefully someone can help me!
 
You also need to pass in any output parameters, otherwise how can you check them in the calling program?

If calling from Query analyzer with your code:

Code:
declare @rowcount int
declare @checknum varchar(50)

select @checknum = '123456789'

exec spGetChecksByCheckNum @checknum, @rowcount output

-- See how many rows there were
select @rowcount
[code]
 
jby1:

Thanks for your post. I ran your code and it worked as intended in Query Analyzer. I can see where you are setting the value for @CheckNum, but still don't quite understand why @RowCount has to be an INPUT parameter as well. In your code, you aren't assigning a value to @RowCount, correct?

By the way, what reference book do you believe is the best on the subject of Stored Procedures that can assist me?

Thank you once again for your assistance!
 
Oh, I see what is happening now! One is not assigning a value to @RowCount, but just the parameter. One needs sort of a place holder for this parameter.

I am using VS.NET 2003 to run the Stored Procedure and now that I set the VALUE for @RowCount to NULL, it works perfectly!

 
I see you have answered your own question!! Glad to be of assistance anyway.

I am afraid that I cannot be of any help regarding a book on writing Stored Procedures, as I have never bought one myself!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top