Hoping for some help on this one as it is far to early in the morning and my brain is not in full working condition as of yet.
The following SQL statement is valid and gives the desired output, but when used in my perl
script it returns the error below.
my $stmt = 'SELECT DATE_FORMAT(completion_time, '%m') as 'month', COUNT(id) as 'total' FROM calls WHERE DATE_FORMAT(completion_time, '%Y') = ? GROUP BY DATE_FORMAT(completion_time, '%m')';
my $sth = database->prepare($stmt);
$sth->execute(params->{year});
Error
Uncaught exception from user code:
Unmatched ) in regex; marked by <-- HERE in m/) <-- HERE as / at /home/dev/Dancer/lib/new.pm line 507.
Compilation failed in require at ./bin/app.pl line 4.
I am using Dancer
and it's Database Plugin but that is working perfectly everywhere else in the app so it is definitely an issue with my syntax or my usage of DATE_FORMAT, but I am not sure as I have not used DATE_FORMAT prior to today.
As always any help is appreciated and thank you in advance.
Looks like your quoting is messed up.
Try something like this:
my $stmt = "SELECT DATE_FORMAT(completion_time, '%m') as 'month', ".
"COUNT(id) as 'total' FROM calls WHERE ".
"DATE_FORMAT(completion_time, '%Y') = ? ".
"GROUP BY DATE_FORMAT(completion_time, '%m')";