Possible Duplicate:
Conversion failed when converting the nvarchar value ‘Internet Explorer 3 original’ to data type int
So I created this following simple stored procedure:
CREATE PROCEDURE test
AS
BEGIN
RETURN 'works!'
END
GO
I then wanted to execute it by firing the following statement:
EXEC test
Why am I getting the following error all the time?
Conversion failed when converting the varchar value 'works!' to data type int.
Oh and btw, (when) is it necessary to have the GO-statement in the end of a stored procedure? I guess it takes no effect here since it will jump out of the procedure when I am returing my @out String.
Multiple values will be returned from Stored Procedure by returning comma separated (delimited) values using Output Parameter. Output Parameter is supported in Stored Procedures of all SQL Server versions i.e. 2000, 2005, 2008, 2008R2, 2012 and 2014.
Return Value in SQL Server Stored Procedure In default, when we execute a stored procedure in SQL Server, it returns an integer value and this value indicates the execution status of the stored procedure. The 0 value indicates, the procedure is completed successfully and the non-zero values indicate an error.
A stored procedure does not have a return value but can optionally take input, output, or input-output parameters. A stored procedure can return output through any output or input-output parameter.
Using RETURN only allows you to return an INTEGER code
You either need to SELECT the value
CREATE PROCEDURE test
AS
BEGIN
SELECT 'works!'
END
or if you want to assign into a variable in the caller, use an OUTPUT parameter
CREATE PROCEDURE test
@outputVal VARCHAR(20) OUTPUT
AS
BEGIN
SET @outputVal = 'works!'
END
DECLARE @val VARCHAR(20)
EXECUTE test @val OUTPUT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With