JobyJ has asked for the wisdom of the Perl Monks concerning the following question:
Using Perl I am parsing an fixed width file and fetching few fields that are being pushed to SQL DB later.
my $Date = 20170121; # Parsed from file my $file = Testfilename; # Parsed from file
Iam then making a connection to the DB and then the below lines of code follows
my $sql = "INSERT INTO TableName(Date,FileName) VALUES($Date,$file)"; my $stmt = $settle_dbh->prepare($sql); $stmt->execute();
Getting an error stating
DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server Driver]Inval +id precision value (SQL-HY104)
Hence I tried to check what's passing in the $sql, the single quotes seem to be missing. Which I feel might be the issue.
print $sql; INSERT INTO TableName(Date,FileName) VALUES(20170121,Testfilename)
Can you please help me on how to get this resolved, may be in two ways which I could think of
1. Convert the date in Perl to format 2017-01-21 00:00:00.000
2. Passing the values in single quotes to SQL DB
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Error passing string date from Perl to MSSQL
by Corion (Patriarch) on Apr 20, 2017 at 07:53 UTC | |
by JobyJ (Initiate) on Apr 20, 2017 at 09:03 UTC | |
by Corion (Patriarch) on Apr 20, 2017 at 09:05 UTC | |
by MidLifeXis (Monsignor) on Apr 20, 2017 at 17:28 UTC | |
by chacham (Prior) on Apr 20, 2017 at 18:34 UTC | |
by cormanaz (Deacon) on Apr 20, 2017 at 18:01 UTC |