I recently had to generate a report listing the details of all orders from a magento store that matched certain parameters.
There was a requirement that the billing address should be included in this, and I wanted to do this all in SQL if possible.
The biggest problem was formatting the address as there is a value in the address table called suffix, which contains the County information, but is not a required value.
As I was adding in line breaks to the select, this meant for all of the orders that did not have the value, then there would be a blank line using a standard CONCAT statement.
What I found was that it is possible to add an IF statement to the CONCAT query, which gives the required result.
This is done like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16