Splitted message query for export into several functions to support all SQL dialects