I have done my stored procedure 101 recently and just wrote a little stored procedure, which looks like following:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[SelectProUserByUsername]
@userName varchar(300)
AS
BEGIN
SET NOCOUNT ON;
SELECT * from ProUser
END
For some reason, SSMS has a reason to believe that my return type is integer. It should in object browser that my stored procedure returns integer
I am not sure what is the reason why it does that. Any ideas?
SQL Server supports both User-Defined Functions and Stored Procedures. Whereas a function takes a number of parameters as input, and returns a single value of a user-defined type as output, a stored procedure is simply a set of connected SQL statements. They can be connected to the rest of the program via input and output parameters, or they can simply modify data, produce result sets, etc, as though the Transact-SQL had been pasted directly into the query.
To quote the Books Online article, a stored procedure can:
That last point is the sense in which a stored procedure "returns an integer", because the return status is always an integer value (with a default of 0). This is controlled by using the RETURN
statement inside the stored procedure.
For instance, if I ran your stored proc above like so:
DECLARE @return_status int;
EXEC @return_status = SelectProUserByUsername 'IMSoP';
SELECT @return_status as status;
I would get an additional result set with status
of 0
; if I added RETURN 1
at the end of the procedure, I would get 1
instead.
SSMS is simply displaying the "return type" to be consistent with functions, but it's always going to be an integer for a stored procedure.
Note that in some contexts, an integer-returning function and a stored procedure could be used interchangeably; for instance the EXECUTE
/EXEC
statement in my example above uses the same syntax for any "module" (procedure, function, etc).
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다