I know your pain.
I have worked with 2 of the biggest EMR vendors in the US in a DBD/report writer role in a hospital environment and have been..uhm..less than impressed with their SQL (DBA specific or language specific) abilities.
We did a lot of smiling and waving.