Error in stored procedure

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
waseem83
Forum Commoner
Posts: 54
Joined: Tue Jun 23, 2009 3:51 am
Contact:

Error in stored procedure

Post by waseem83 »

HI every body,
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
 
Can any body help me why this error come?
Thanks in advance.
Last edited by Weirdan on Wed Jun 24, 2009 6:32 am, edited 1 time in total.
Reason: added [code=sql] tags
Post Reply