Skip to Content.
Sympa Menu

freetds - [freetds] Need help with SQL server stored procedure output?

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Gaurav Nangia" <gnangia AT mspintl.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: [freetds] Need help with SQL server stored procedure output?
  • Date: Fri, 18 Jul 2003 12:04:22 -0400

Hi all,

I am using freetds 0.61 with DBD::Sybase on Redhat linux to connect to SQL
Server 7.0. Connection works fine and I can run select statments to do
queries against any of the databases. However, I am having an issue with
running a stored procedure that RETURNS A VALUE. How do I retrieve that
value. I would appreciate if somebody could provide some insight. So far
the gist of my program is as follows -

TEST Stored Procedure that was created -
CREATE PROCEDURE TEST @results numeric(9,4) OUTPUT
AS

BEGIN
SELECT @results = 9999.9999

END

Here is the sql statement I use to retrieve the result at a sql command
line.
declare @mytest numeric(9,4)
exec TEST @results=@mytest OUTPUT
print @mytest

Now here is the perl script that I use
#!/usr/bin/perl

use DBI;
$dbh = DBI->connect('DBI:Sybase:server=DEV;', $user, $passwd) or die "Cannot
connect:$@\n";
$sql = ("declare \@test numeric(9,4) exec TEST \@results=\@test OUTPUT");
$sth=$dbh->prepare($sql);
$sth->execute;
while(@d = $sth->fetchrow_array)
{
foreach $xyz(@d)
{
print "REsult=>$xyz<=\n";
}
}
This should print the hardcoded value 9999.9999 but prints out 0 which I
think is a successful return code. Can anyone please help me out.

Regards,
Gaurav






Archive powered by MHonArc 2.6.24.

Top of Page