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!

How to Get the OUTPUT Parameter From a Stored Procedure

Status
Not open for further replies.

NYZ

Programmer
Mar 3, 2003
1
CA
I am migrating Sybase 11.0 to SQL Server 2000. In script of Powerbuilder 6.5, I need to excute a stored procedure which has an output parameter. It has no problem when I connected to the Sybase database. But when I connected to SQL Server with the same code. I got this error:"Invalid character value for cast specification."
Here's the script in Powerbuilder:

//BEGIN
long ll_scale_id
DECLARE get_scale_id PROCEDURE FOR dbo.get_next_scale_id
@scale_id = 0 output
USING SQLCA;
EXECUTE get_scale_id;
//END

I checked help information in Powerbuilder, and changed my code according to the syntax, unfortunately, it didn't work for SQL Server 2000 either:

//Begin
LONG ll_scale_id
DECLARE get_scale_id PROCEDURE FOR dbo.get_next_scale_id
@scale_id = :ll_scale_id OUTPUT USING SQLCA;
// I also tried DECLARE get_scale_id PROCEDURE FOR dbo.get_next_scale_id @scale_id = :ll_scale_id OUT;

EXECUTE get_scale_id;
//End

After running EXECUTE statement, SQLCA.SQLCode = -1, SQLERRTEST is "SQLSTATE = 22005[Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification"

Here's the stored procedure created in SQL Server 2000:

CREATE proc dbo.get_next_scale_id
@scale_id int output
AS
BEGIN
UPDATE Options
SET value = value + 1
WHERE name = 'SCALE_ID'

IF @scale_id IS NULL or @scale_id = 0
IF @@error != 0
BEGIN
SELECT @scale_id = -1
RETURN
END
SELECT @scale_id = value
FROM Options
WHERE name = 'SCALE_ID'
IF @@error != 0 or @scale_id = 0 or @scale_id is null
BEGIN
SELECT @scale_id = -1
END
RETURN
END
 
Something might help you:
Problem occured with datatype casting.
Why you use long to declare your variable ll_scale_id? Did you try to just use int?
And you can try use string/char, it will be more simple for database interface. I mean you change the stored procedure to convert the output as a char(x) and you see if you can get the output by your string variable.

Good luck!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top