yeah I tried it on my laptop with version 5.10 of perl and no its not the version of dbi I am at 1.601 upgraded to 1.602 but no difference at all, here is my code + my error file.
use OLE;
use DBI;
use DBD::ODBC;
use Mail::Sender;
my $trace_level=1;
my $trace_file='tracefile.txt';
DBI->trace($trace_level,$trace_file);
#### lnitialization of Global Variables & Arrays ####
my $debug =0;
my $t = time;
(my $sec, my $min, my $hour, my $mday, my $mon, my $year, my $wday, m
+y $yday, my $isdst)=localtime($t);
$year = $year + "1900";
my $SQLServer = "servername";
my $DB = "dbname";
my $SQLUname = "username";
my $SQLpass="password";
my $field1="ClassSchedule.EventDate AS EventDate";
my $field2="DATEDIFF(Day,{fn NOW()},ClassSchedule.EventDate) A
+S Until,";
my $field3="DATEDIFF(Day,ClassRoster.Enrolled, ClassSchedule.EventDat
+e) AS Since,";
my $field4="Classes.Duration AS Duration, Classes.Topic AS Topic, Cla
+sses.Description AS Description,
ClassLocation.Location AS Location,
ClassLocation.Address AS Address,
ClassLocation.Directions AS Directions,
ClassLocation.Map AS Map,
ClassRoster.idEnrollee AS idEnrollee,
ClassRoster.System AS System,
ClassRoster.Account AS Account,
ClassRoster.PublicID AS PublicID,
ClassRoster.Name AS Name,
ClassRoster.Email AS emailAddress";
my $field5="ClassSchedule";
my $field6="Classes ON ClassSchedule.id_Class = Classes.idClass";
my $field7="ClassRoster ON ClassSchedule.idEvent = ClassRoster.id_Eve
+nt";
my $field8="ClassLocation ON ClassSchedule.id_Location = ClassLocatio
+n.idLocation";
my $field9condition="ClassSchedule.EventDate > { fn NOW() }) A
+ND
(ClassRoster.Cancelled IS NULL) AND
(ClassRoster.Reminded IS NULL) AND
(DATEDIFF(dd, ClassRoster.Enrolled, ClassSchedule.EventD
+ate) > 7) AND
(NOT (DATEPART(dw, { fn NOW() }) IN (1, 7))) AND
(DATEDIFF(dd, { fn NOW() }, ClassSchedule.EventDate) < 7
+)";
# Connect to the database
# See footnote
my $dbh = DBI->connect("dbi:ODBC:driver=SQL Server;Server=VASVCSSQL;da
+tabase=MLXhelp;uid=$SQLUname;pwd=$SQLpass;") or die "Couldn't open d
+atabase: $DBI::errstr; stopped";
print "connected finally\n";
# Prepare the SQL query for execution
my $sth=$dbh->prepare("SELECT $field1,$field2,$field3,$field4 from $fi
+eld5 INNER JOIN $field6 INNER JOIN $field7 INNER JOIN $field8 WHERE $
+field9condition");
# Execute the query
$sth->execute() or die "Couldn't execute statement: $DBI::errstr; stop
+ped";
while (my ($field1)=$sth->fetchrow_array())
{
print "Field 1: $field1 \n";
}
$sth->finish();
$dbh->disconnect();
DBI 1.602-ithread default trace level set to 0x0/1 (pid 5692) at t
+est3.pl line 12
-> DBI->connect(dbi:ODBC:driver=SQL Server;Server=VASVCSSQL;databa
+se=MLXhelp;uid=Frank;pwd=fu3go;, , ****)
-> DBI->install_driver(ODBC) for MSWin32 perl=5.010000 pid=5692 ru
+id=0 euid=0
install_driver: DBD::ODBC version 1.15 loaded from C:/Perl/site
+/lib/DBD/ODBC.pm
<- install_driver= DBI::dr=HASH(0x3376c8c)
!! warn: 0 CLEARED by call to default_user method
<- default_user(undef, undef, ...)= ( undef undef ) [2 items] at D
+BI.pm line 625
<- connect('driver=SQL Server;Server=VASVCSSQL;database=MLXhelp;ui
+d=Frank;pwd=fu3go;', undef, ...)= DBI::db=HASH(0x33771ac) at DBI.pm l
+ine 637
info: '' '[Microsoft][ODBC SQL Server Driver][SQL Server]Change
+d database context to 'MLXhelp'. (SQL-01000)
[Microsoft][ODBC SQL Server Driver][SQL Server]Changed language settin
+g to us_english. (SQL-01000)' (err#0)
<- STORE('PrintError', 1)= 1 at DBI.pm line 689
info: '' '[Microsoft][ODBC SQL Server Driver][SQL Server]Change
+d database context to 'MLXhelp'. (SQL-01000)
[Microsoft][ODBC SQL Server Driver][SQL Server]Changed language settin
+g to us_english. (SQL-01000)' (err#0)
<- STORE('AutoCommit', 1)= 1 at DBI.pm line 689
info: '' '[Microsoft][ODBC SQL Server Driver][SQL Server]Change
+d database context to 'MLXhelp'. (SQL-01000)
[Microsoft][ODBC SQL Server Driver][SQL Server]Changed language settin
+g to us_english. (SQL-01000)' (err#0)
<- STORE('Username', undef)= 1 at DBI.pm line 692
info: '' '[Microsoft][ODBC SQL Server Driver][SQL Server]Change
+d database context to 'MLXhelp'. (SQL-01000)
[Microsoft][ODBC SQL Server Driver][SQL Server]Changed language settin
+g to us_english. (SQL-01000)' (err#0)
<> FETCH('Username')= undef ('Username' from cache) at DBI.pm line
+ 692
info: '' '[Microsoft][ODBC SQL Server Driver][SQL Server]Change
+d database context to 'MLXhelp'. (SQL-01000)
[Microsoft][ODBC SQL Server Driver][SQL Server]Changed language settin
+g to us_english. (SQL-01000)' (err#0)
#removed connectstring for security
<- connected('dbi:ODBC:driver=SQL;')= undef at DBI.pm line 698
<- connect= DBI::db=HASH(0x33771ac)
info: '' '[Microsoft][ODBC SQL Server Driver][SQL Server]Change
+d database context to 'MLXhelp'. (SQL-01000)
[Microsoft][ODBC SQL Server Driver][SQL Server]Changed language settin
+g to us_english. (SQL-01000)' (err#0)
<- STORE('dbi_connect_closure', CODE(0x3376bdc))= 1 at DBI.pm line
+ 707
!! info: '' CLEARED by call to prepare method
<- prepare('SELECT ClassSchedule.EventDate AS EventDate,DATEDIFF(D
+ay,{fn NOW()},ClassSchedule.EventDate) AS Until,,DATEDIFF(Day,ClassRo
+ster.Enrolled, ClassSchedule.EventDate) AS Since,,Classes.Duration AS
+ Duration, Classes.Topic AS Topic, Classes.Description AS Description
+,
ClassLocation.Location AS Location,
ClassLocation.Address AS Address,
ClassLocation.Directions AS Directions,
Cl...')= DBI::st=HASH(0x33773dc) at test3.pl line 55
!! ERROR: 1 '[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1
+: Incorrect syntax near ','. (SQL-42000)
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not
+be prepared. (SQL-42000)' (err#2)
<- execute= undef at test3.pl line 57
ERROR: 1 '[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1
+: Incorrect syntax near ','. (SQL-42000)
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not
+be prepared. (SQL-42000)' (err#2)
<- DESTROY(DBI::st=HASH(33772ec))= undef at test3.pl line 57
ERROR: 1 '[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1
+: Incorrect syntax near ','. (SQL-42000)
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not
+be prepared. (SQL-42000)' (err#0)
<- DESTROY(DBI::db=HASH(337711c))= undef at test3.pl line 57
!! ERROR: 1 CLEARED by call to disconnect_all method
<- disconnect_all= '' at DBI.pm line 715
! <- DESTROY(DBI::dr=HASH(3376c8c))= undef during global destruction
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.