Hello,

I have some code that I have run against MS SQL Server and Sybase ASE successfully. When I try to run it against a Sybase IQ server, there is a problem.

A temp table is created with a single varchar(25) field. Then a list of numbers are read from a file, leading zero's are pre-pended and I attempt to insert them one by one into the temp table.

The error returned is:

DBD::Sybase::st execute failed: Server message number=21 severity=14 state=0 line=0 text=SQL Anywhere Error -1000187: Unable to implicitly convert column 'PAT_MRN_ID' to datatype (varchar) from datatype (integer).

The code is:

my $crTmpMRN = qq{create table #mrns (PAT_MRN_ID varchar(25))}; $dbh->do($crTmpMRN); my $mrn; my $name; my $fileRowCount=0; my $dbRowCount=0; my $distinctMRNCount = 0; #for some reason SybaseIQ is trying to insert $mrn as an integer my $insertMRNQuery = qq{insert #mrns (PAT_MRN_ID) values (?)}; my $sth=$dbh->prepare($insertMRNQuery); open (MRNFILE,"$baseDir$mrn_file") or die "Can't read file $baseDir$mr +n_file [$!]\n"; while (<MRNFILE>) { chomp ($_); ($mrn,$name)=split('\t',$_); #uses 10 character MRNs $mrn = substr '0000000000'.$mrn, -10; $sth->execute($mrn); $fileRowCount ++; print qq{'$mrn'\n}; } close (MRNFILE); print '$fileRowCount: '.$fileRowCount."\n";

I don't know much about the odbc drivers - I think it is odd that the error says "SQL Anywhere", but I am using the connection information that I was given. I have figured out a workaround - creating two columns in the temp table, inserting the numbers converted to varchar, then updating the values to the second column in the temp table. But really, I want to understand why it is attempting to insert $mrn as a numeric rather than a string.

Any help would be greatly appreciated!!


In reply to Using perl dbi and Sybase IQ doing insert with placeholder getting datatype error by ckbbkc

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.