Hello,
I am trying to get data from a Sybase DB using DBI and DBD::ODBC.
I have tested the connection using fixed values in the code, but when I try to pass a variable or placeholder, as in the code below, I get the following error message:
DBD::ODBC::st execute failed: [MERANT][ODBC Sybase ASE driver][SQL Ser +ver]Implicit conversion from datatype 'VARCHAR' to 'NUMERIC' is not a +llowed. Use the CONVERT function to run this query.

And I can't seem to locate anything on the CONVERT function in DBI.

Here's the query I am trying to run:
use DBI; my $dbh = DBI->connect('dbi:ODBC:Data Source', 'username', 'passwor +d', {RaiseError => 1,}); my $sth = $dbh->prepare('SELECT customercode FROM customerorde +rs WHERE ordercode = ?') or die "Couldn't prepare statement: " . $dbh->errstr; print "Enter ordercode> "; while ($ordercode = <>) { # Read input from the user my @data; chomp $ordercode; $sth->execute($ordercode) # Execute the query or die "Couldn't execute statement: " . $sth->errstr; # Read the matching records and print them out while (@data = $sth->fetchrow_array()) { my $customercode = $data[1]; my $ordercode = $data[2]; print "\t $customercode $ordercode\n";

Now I've searched through PerlMonks and on the Web and I can't find any solution to this problem, other than suggestions that I use a different DBD driver, such as DBD::Sybase. I have downloaded and installed that driver but I am having trouble getting it to work.
I also tried bind_param, as follows:
$sth->bind_param(1, $ordercode, SQL_INTEGER); with no success.
Has anyone come up with a way to pass variables in a query to a Sybase DB using DBD::ODBC on Win32?

Thank you,
David MacDougall
Charleston, SC

In reply to Win32 - DBD-ODBC - Sybase by dmacdou

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.