Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Best practices and any way to have Perl Tidy clean it up

by talexb (Canon)
on Apr 14, 2013 at 21:04 UTC ( #1028648=note: print w/replies, xml ) Need Help??

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

my $sth = $dbh->prepare(" SELECT, 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 ");
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.

There is no one right way to format SQL, but this approach seems fairly clear.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028648]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2018-02-18 18:47 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (256 votes). Check out past polls.