SET @num := 0; SET @id := -1; SELECT e.*, y.ChallengerID, CASE WHEN ep.isChampion IS TRUE THEN TRUE ELSE FALSE END AS isCurrentChampion FROM ( . . . #### DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @id := -1; SELECT e.*, y.ChallengerID, CASE WHEN ep.isChampion IS TRUE THE' at line 2 #### #!/usr/bin/env perl use strict; use warnings; use DBI; use Data::Dumper; # MYSQL CONFIG VARIABLES my $host = "XYZ"; my $db = "XYZ"; my $dbuser = "XYZ"; my $dbpw = "XYZ"; # CONNECT TO MYSQL my $dbh = DBI->connect("DBI:mysql:$db", $dbuser, $dbpw) || die "Could not connect to database: $DBI::errstr"; my $myquery; $myquery = "SET \@num := 0, \@id := -1;"; my $sth = $dbh->prepare($myquery); $sth->execute(); # Retrieve all open tests my $file = "../sql/code.sql"; { local $/ = undef; open FILE, $file or die "Couldn't open file: $!"; $myquery = ; close FILE; } print "\nSQL scheduling query constructed... executing..."; $sth = $dbh->prepare($myquery); $sth->execute();