I am trying to get a query to work in Perl, but it can't seem to handle it and I don't really know why. I am using DBI, and it gives me a MySQL syntax error at the start of the second part. The query has 4 parts as follows:

This creates a temporary table with all the fields I require. The next part take values from other tables (`Timesheets_Jobs` and `employees`) and inserts filtered results into the temporary table as follows:

Note that "20080903" is a value that gets determined by variables selected by the user. The last part of the query selects the data from the temporary table (using a reference to a table called `jobs`) and sorts it as I require:

The query itself works fine in MySQL command line, and in phpMyAdmin, and typically runs in under 2 mS, but it seems that DBI has a problem with multiple steps like this. I have also tried including the word "VALUES", and brackets, before the selections for inserting, but to no avail.

Well, it wasn't the concatenation, but believe it or not, the mess of SQL I initially posted was what I was trying to use - in one query. After reading your post "Do you believe that line lengths of 400+ chars is readable?", I thought "maybe computers feel the same", and I decided to break up the query into the individual steps, as such:

Why would you think executing 4 sql statements as if it were 1 statement would work? Even when executing them from the command line, they are executed as 4 separate sql statements (the semi-colon indicate the end of an sql statement).