in reply to What is wrong with this mSQL insert?

If you haven't yet googled for "Invalid character value for cast", you might want to try that, in case there might be anything relevant that isn't even perl-related.

Apart from that, whenever people say "I tried this and that", but they don't show the actual code that they tried, I tend to get a little skeptical. I'd like to suggest the following, which provides not only (I hope) a reliable test, but also some ideas for making the code easier to manage -- using arrays and hashes to keep things better organized:

use strict; use warnings; use DBI; ### list the db-table field names as an array my @flds = qw( rec_num src_file src_host init_status cdr_day last_modified city state cname vname npa nxx ocn lata lata_name pdd zone_id cdrs_seq file_seq gc_id ); my ( %testdata, %realdata ); ### use hashes to store data ### read test data from within the script file, put it in a hash: my @test = <DATA>; chomp @test; @testdata{@flds} = @test; ### this is a "hash-slice" assignment ### ... do whatever assigns "real" values to your variables ... my ( $rec_num, $src_cdr_file, $host, $init_status, @f, $city, $state, $cname, $vname, $npa, $nxx, $ocn, $lata, $lata_name, $pdd ); ### ... and put the real data into a hash as well: @realdata{@flds} = ( $rec_num, $src_cdr_file, $host, $init_status, $f[20], $f[4], $city, $state, $cname, $vname, $npa, $nxx, $ocn, $lata, $lata_name, $pdd, @f[0..3] ); ### make sure the "real" data matches the test data my $diff = 0; for ( @flds ) { if ( $realdata{$_} ne $testdata{$_} ) { warn "Field $_: Real >>$realdata{$_}<< vs. Test >>$testdata{$_ +}<<\n"; $diff++; } } die "No point going any further\n" if ( $diff ); ### If the test data worked in the past, the real data should work now +: my $database_username = "USER"; my $database_password = "PASS"; my $msdsn = q/dbi:ODBC:DRIVER={SQL Server};Server=10.0.0.5;attr=value/ +; my $dbh = DBI->connect( $msdsn, $database_username, $database_password + ) or die "ERROR"; $dbh->do("use db_name") or log_die("$DBI::errstr"); ### build the sql statement based on the @flds array my $fldnames = join( ',', @flds ); my $valqmrks = join( ',', ('?') x @flds ); my $SQL = "INSERT INTO iCDRSbw ($fldnames) VALUES ($valqmrks)"; my $sth = $dbh->prepare( $SQL ); $sth->execute( @realdata{@flds} ) or warn "That should have worked...\ +n"; __DATA__ 1 icdr.5_5_5B.0.1.200712170000.052964.0 127.0.0.1 Unprocessed 2007-12-17 00:00:47 2007-12-17 00:00:47 NA NA 999 999 1 1 1 1 1 1 AAAAC0dlvAgiIAABC7Przw.7591990
The idea here is that you have a test script that allows you to make sure that the values actually loaded to your variables contain exactly what you are expecting, by comparing them all to test values that are included in the script and are based directly on values that you know ought to work.

Note that I've posted the test script in such a way that it would pass "perl -cw" on my own machine -- I eliminated the dependencies on things you didn't show us in the OP -- so as you add stuff to populate your "real" data variables, if you get syntax errors or warnings, you know it's because of stuff you've added.