in reply to Best practices and any way to have Perl Tidy clean it up
I have my own preferences on how SQL should get tidied up, and what you have is close. However, you probably shouldn't expect perltidy to handle SQL as well as Perl. I'd run perltidy on the code, then go back and organize the SQL separately.
And my preference for formatting this chunk would be
This format highlights all of the key words, leaves spaces between each of the resulting columns, indents the 'AND' clauses to clarify the filtering, and generally exposes as much of the logic behind the query as possible.my $sth = $dbh->prepare(" SELECT t.id, t.emp_name, t.emp_email, t.req_status, t.date_requested, t.mngr_email, t.date_submitted, ( SELECT GROUP_CONCAT ( ( CASE WHEN req_status = 'Approved' THEN emp_name END ) SEPARATOR ', ' ) FROM requests s WHERE s.date_requested = t.date_requested ) AS approved FROM requests t WHERE req_status = 'Pending' AND mngr_email = '$filter' AND date_requested >= '$date' ORDER BY emp_name, date_requested ");
There is no one right way to format SQL, but this approach seems fairly clear.
|
|---|