Hi,
I've been trying to write a stored proc to no avail. I'm trying to set a local variable and every time I try to execute the stored proc I get the following error:
Running [dbo].[StoredProcedure2].
Conversion failed when converting the nvarchar value 'TEST2' to data type int.
No rows affected.
(0 row(s) returned)
@.RETURN_VALUE =
Finished running [dbo].[StoredProcedure2].
Here's the code (which I skimmed down to try and pinpoint where the issue was).
Initially, I was trying to assign a numeric string value stored as nvarchar(10) and anytime the value would be over '2147999999' (in that area) it would bomb... Now even this simple code won't work and I can't understand why. If anyone would be kind enough to enlighten me ;-)
ALTER PROCEDURE dbo.StoredProcedure2
AS
DECLARE @.ME NVARCHAR(10);
SET @.ME = 'TEST2';
RETURN @.ME
u must use Print/Select instead of Return.
fromBOL
RETURN
Exits unconditionally from a query or procedure. RETURN is immediate and complete and can be used at any point to exit from a procedure, batch, or statement block. Statements following RETURN are not executed.
Syntax
RETURN [ integer_expression ]
alter PROCEDURE dbo.StoredProcedure2
AS
DECLARE @.ME NVARCHAR(10);
SET @.ME = 'TEST2';
select @.me
Madhu
|||The value following the RETURN keyword MUST be an integer value.
Strings are not allowable RETURN values.
Instead use:
Code Snippet
ALTER PROCEDURE dbo.StoredProcedure2
AS
DECLARE @.ME NVARCHAR(10);
SET @.ME = 'TEST2';
SELECT @.Me
GO |||It always better to use OUTPUT parameter, or Select statement to get the single row & column data from the SP. Return only supports integer.
NOTE:
PRINT – you can’t get the result on the UI. It will get suppressed.
No comments:
Post a Comment