I want to make a stored procedure for select query which will take table name ,columns,and where clause as its parameters.
But when i run script following errors come.
#1064 - 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 '' at line 5
The script is as follows.
Code: Select all
CREATE PROCEDURE SelectTable(IN strTableName VARCHAR(20),IN strColumns VARCHAR(100), IN strWhere VARCHAR(100),IN strOrderBy VARCHAR(100), IN strGroupBy VARCHAR(100),IN nLimit VARCHAR(100),IN nLimitEnd VARCHAR(20))
BEGIN
IF strWhere != NULL
then
SELECT DISTINCT strColumns FROM strTableName WHERE strWhere;
else
SELECT DISTINCT strColumns FROM strTableName;
END IF;
IF strGroupBy != NULL
then
strQry += GROUP BY strGroupBy;
END IF;
IF strOrderBy != NULL
then
strQry += ORDER BY strOrderBy;
END IF;
IF nLimitEnd != NULL
then
strQry += LIMIT nLimit,nLimitEnd;
END IF;
IF nLimit != NULL
then
strQry += LIMIT nLimit;
END IF;
}
END
Thanks in advance.