简体   繁体   中英

Issue with binding parameters for MS SQL Server Stored Procedure in Perl DBI

Getting error while executing the stored procedure from perl. I am able to connect to the MS SQL server from perl without any issues. But when I execute the procedure with the following binding parameters I am getting the error

[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '@id'. (SQL-42000)

this 'id' is the first parameter. When I look at the procedure it is fine. Anyone have any thoughts on this error?

Code

#GetStatusDescription(?, ?, ?) - id - LONG, status - VARCHAR, description - VARCHAR
my $sth = $dbh -> prepare('exec GetStatusDescription(?, ?, ?)');
my $str1, my $str2;
my $intid = 11122;
use DBI qw(:sql_types);
$sth->bind_param(1, $intid, DBI::SQL_INTEGER); 
$sth->bind_param_inout(2, \$str1, DBI::SQL_VARCHAR); 
$sth->bind_param_inout(3, \$str2, DBI::SQL_VARCHAR); 
$sth->execute() or die $dbh -> errstr;

If you're calling to a stored procedure, those don't take parentheses in SQL Server. that is, you want:

my $sth = $dbh -> prepare('exec GetStatusDescription ?, ?, ?');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM