Making variable field names
- From: "Peter Jamieson" <ldolan@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 18 Jan 2008 04:09:07 GMT
I have many tables of results, a sample record looks like as below
in my code together with fields in the db.
The problem is this. Not every table I receive has the same fields.
Sometimes there are fields, "test4", "test5" for example.There is always
a fixed number of 7 fields.
Is it possible to have my code change the INSERT INTO statement so that the
fields change
depending on the fields in each table?....of course the db will have all
possible fields
included.
In other words, can the field names be variables?...if so what is the syntax
for this?
Any help appreciated!
#!/usr/bin/perl -w
use strict;
use warnings;
use Win32::ODBC;
use dbi;
my $mdb = "Treatment.mdb";
my $dns = "driver=Microsoft Access Driver (*.mdb);dbq=$mdb";
# Connect to the mdb and prepare request
my $dbh = DBI->connect("dbi:ODBC:$dns", ',') or die "Connection to $mdb
failed!\n";
# sample results
$mdate = '17/1/2008'; $venue = 'ICPM'; $patient = 'G Gomez'; $dob =
'21/08/1977'; $test1 = 88.5;
$test2 = 75.1; $test3 = 81.9;
# Load the results into the database
my $input = $dbh->prepare("INSERT INTO
Treatment_table(mdate,venue,patient,dob,test1,test2,test3)
VALUES (?,?,?,?,?,?,?)");
$input->execute( $mdate, $venue, $patient, $dob, $test1, $test2, $test3);
$dbh->disconnect();
.
- Follow-Ups:
- Re: Making variable field names
- From: David Filmer
- Re: Making variable field names
- Prev by Date: Re: Problem directing BCP Error to Error file
- Next by Date: Re: To update one file with the another file's data..
- Previous by thread: FAQ 8.11 How do I decode encrypted password files?
- Next by thread: Re: Making variable field names
- Index(es):