Problem with Raw SQL Report Query
5 September, 2014
The following is valid SQL:
[code]
SET @start = '2014-09-01 00:00:00';
SET @end = '2014-09-30 23:59:59';
SELECT
CONCAT(u.first, ' ', u.last) AS 'Full Name',
c.outgoing AS '# of Outgoing Calls',
c.incoming AS '# of Incoming Calls',
td.transfers AS '# of Transfers',
td.deals AS '# of Deals',
td.dealsAmount AS 'Amount of Deals'
FROM teamLenderUsers tlu
INNER JOIN users u ON tlu.lenderUserId = u.id
LEFT OUTER JOIN (
SELECT a.oldLenderUserId AS 'lenderUserId',
COUNT(a.id) AS 'transfers',
COUNT(d.id) AS 'deals',
SUM(d.amount) AS 'dealsAmount'
FROM assignments a
LEFT OUTER JOIN deals d ON a.borrowerId = d.borrowerId AND d.deleted IS NULL AND d.dateClosed IS NOT NULL
INNER JOIN teamLenderUsers tlu ON a.oldLenderUserId = tlu.lenderUserId AND (tlu.deleted IS NULL OR tlu.deleted > @start)
WHERE a.deleted IS NULL
AND a.created BETWEEN @start AND @end
GROUP BY a.oldLenderUserId
) td ON u.id = td.lenderUserId
LEFT OUTER JOIN (
SELECT
a.lenderUserId AS 'lenderUserId',
SUM(IF(a.type = 'outgoing', 1, 0)) AS 'outgoing',
SUM(IF(a.type = 'incoming', 1, 0)) AS 'incoming'
FROM calls a
INNER JOIN teamLenderUsers tlu ON a.lenderUserId = tlu.lenderUserId AND (tlu.deleted IS NULL OR tlu.deleted > @start)
WHERE a.deleted IS NULL
AND a.created BETWEEN @start AND @end
GROUP BY a.lenderUserId
) c ON u.id = c.lenderUserId
WHERE tlu.teamId = 32
AND tlu.role IN ('tl+', 'ls')
AND (tlu.deleted IS NULL OR tlu.deleted > @start);
[/code]
However, it fails to validate when I input it in the SQL Report builder with the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @end = '2014-09-30 23:59:59';
SELECT
CONCAT(u.first, ' ', u.last) AS '' at line 2
Can anyone tell me what Yellowfin expects here?
[code]
SET @start = '2014-09-01 00:00:00';
SET @end = '2014-09-30 23:59:59';
SELECT
CONCAT(u.first, ' ', u.last) AS 'Full Name',
c.outgoing AS '# of Outgoing Calls',
c.incoming AS '# of Incoming Calls',
td.transfers AS '# of Transfers',
td.deals AS '# of Deals',
td.dealsAmount AS 'Amount of Deals'
FROM teamLenderUsers tlu
INNER JOIN users u ON tlu.lenderUserId = u.id
LEFT OUTER JOIN (
SELECT a.oldLenderUserId AS 'lenderUserId',
COUNT(a.id) AS 'transfers',
COUNT(d.id) AS 'deals',
SUM(d.amount) AS 'dealsAmount'
FROM assignments a
LEFT OUTER JOIN deals d ON a.borrowerId = d.borrowerId AND d.deleted IS NULL AND d.dateClosed IS NOT NULL
INNER JOIN teamLenderUsers tlu ON a.oldLenderUserId = tlu.lenderUserId AND (tlu.deleted IS NULL OR tlu.deleted > @start)
WHERE a.deleted IS NULL
AND a.created BETWEEN @start AND @end
GROUP BY a.oldLenderUserId
) td ON u.id = td.lenderUserId
LEFT OUTER JOIN (
SELECT
a.lenderUserId AS 'lenderUserId',
SUM(IF(a.type = 'outgoing', 1, 0)) AS 'outgoing',
SUM(IF(a.type = 'incoming', 1, 0)) AS 'incoming'
FROM calls a
INNER JOIN teamLenderUsers tlu ON a.lenderUserId = tlu.lenderUserId AND (tlu.deleted IS NULL OR tlu.deleted > @start)
WHERE a.deleted IS NULL
AND a.created BETWEEN @start AND @end
GROUP BY a.lenderUserId
) c ON u.id = c.lenderUserId
WHERE tlu.teamId = 32
AND tlu.role IN ('tl+', 'ls')
AND (tlu.deleted IS NULL OR tlu.deleted > @start);
[/code]
However, it fails to validate when I input it in the SQL Report builder with the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @end = '2014-09-30 23:59:59';
SELECT
CONCAT(u.first, ' ', u.last) AS '' at line 2
Can anyone tell me what Yellowfin expects here?
It appears I can't edit my post, however I thought I should clarify that this query is being run against MySQL 5.5.38.
Thanks.
Thanks.
Hi,
It looks like you're trying to use T-SQL in the Yellowfin report builder.
Unfortunately we only support standard SQL for freehand SQL reports/calc fields.
The only way to use T-SQL in Yellowfin is to create a stored procedure in your DB, and then use the create view > Stored Procedure .
Sorry for the bad news, and hope this explains what you're seeing.
Please let me know if you have any questions on this.
Regards,
David
It looks like you're trying to use T-SQL in the Yellowfin report builder.
Unfortunately we only support standard SQL for freehand SQL reports/calc fields.
The only way to use T-SQL in Yellowfin is to create a stored procedure in your DB, and then use the create view > Stored Procedure .
Sorry for the bad news, and hope this explains what you're seeing.
Please let me know if you have any questions on this.
Regards,
David