I have a mysql stored procedure like this:
CREATE DEFINER=`root`@`localhost` PROCEDURE `accounts_summary_by`(
IN **created_by** int(10)
)
BEGIN
SET group_concat_max_len=2048;
SET @sql = NULL;
SELECT
GROUP_CONCAT(
DISTINCT CONCAT(
'MAX(IF(fiscal_year = ''',
fiscal_year,
''', amount, 0)) AS ',
CONCAT("'",fiscal_year,"'")
)
) INTO @sql
FROM
net_savings;
SET @sql = CONCAT('SELECT accounts.id,
accounts.account,
accounts.region,
accounts.cluster,
accounts.industry, ,'
,@sql,
'FROM net_savings join accounts
on accounts.id = net_savings.account_id
Where accounts.user_id = **created_by**
GROUP BY accounts.account,net_savings.account_id
ORDER BY accounts.id');
PREPARE statement FROM @sql;
EXECUTE statement;
DEALLOCATE PREPARE statement;
END
But upon calling the procedure like these:
CALL accounts_summary_by(2)
2 is a user_id reference to another table called users.
It gave me an error. Please help as I can't find any fixed to my problem.
0 72 23:41:12 CALL `buckets`.`accounts_summary_by`(1) Error Code: 1054. Unknown column 'created_by' in 'where clause' 0.000 sec
created_byis a field/table identifier,@created_bywould be your parameter.accounts.industry, ,''is not a symbol used to denote field identifiers (such as aliases), use`(the one with the~key.)