Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to automate a large number of txt files to be imported from Perl to a SQL Server using DBI?
    primarykey
    data
    text
    <p>I have attempted to transfer one txt file into a SQL Server from Perl, but I now need to create a DB in SQL that combines hundreds of txt files. Is there an automated way of doing this to save manually transferring all the txt files? I will insert my attempt of coding one txt file. I believe I need to use Bulk Insert to achieve this but I am unsure what code to use. Any advice on the problem would be really appreciated, and if there is anymore code you wish to see or a specific thing I forgot to mention then please comment and I will edit. Thank you.</p> <pre><code>#!/usr/bin/perl -w use strict; use DBI; use Carp; # Connect to the data source and get a handle for that connection. my $dbh = DBI-&gt;connect('dbi:ODBC:RegressionDBS') || confess "Connection Failed: $DBI::errstr"; # This query generates a result set with one record in it. my $sql = "SELECT 1 AS test_col"; my $tablename = "RegressionTable"; open(FH, "newregression.txt") || die "cant open file"; my $Sqlh = $dbh-&gt;prepare("INSERT INTO RegressionTable (Ticker, TradeDate, HighPrice, LowPrice, TradePrice, TotalVolume, TotalValue) VALUES (?,?,?,?,?,?,?);") || confess $DBI::errstr; while (my $line = &lt;FH&gt; ) { $line =~/^(.*)(..)(..)$/; my ($curTicker, $wTradeDate, $wHighPrice, $wLowPrice, $wTradePrice, $wTotalVolume, $wTotalValue); $curTicker=$1 #$wTradeDate= $wHighPrice=$2; $wLowPrice=$1; #$wTradePrice=$1; #$wTotalVolume=$1; #$wTotalValue=$4; $Sqlh-&gt;execute($curTicker, $wTradeDate, $wHighPrice, $wLowPrice, $wTradePrice, $wTotalVolume, $wTotalValue) || confess $DBI::errstr; } $Sqlh-&gt;finish(); $dbh-&gt;disconnect(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload