I had created following procedure.
DELIMITER ;;
DROP PROCEDURE IF EXISTS getAllPortfoliosDemo;;
CREATE PROCEDURE getAllPortfoliosDemo( IN keyid INT(10))
BEGIN
DECLARE whereString char(100);
IF (keyid > 0 ) THEN
SET whereString = CONCAT( ' WHERE pkid = ', keyid );
ELSE
SET whereString = ' WHERE 1 ';
END IF;
SELECT pkid, title FROM Portfolio whereString;
END ;;
this query returns no error. it works well without parameters. for eg CALL getAllPortfoliosDemo(); works. but it didn't works with a parameter. for eg CALL getAllPortfoliosDemo(5); didn't returns any row.
also i tried the following alternate query
DELIMITER ;;
DROP PROCEDURE IF EXISTS getAllPortfoliosDemo;;
CREATE PROCEDURE getAllPortfoliosDemo( IN keyid INT(10))
BEGIN
DECLARE whereString char(100) DEFAULT NULL;
IF (keyid > 0 ) THEN
SET whereString = CONCAT( ' AND pkid = ', keyid );
END IF;
SET @SQLstmt = CONCAT('SELECT pkid, title FROM Portfolio ', whereString) ;
PREPARE SQLbase FROM @SQLstmt;
EXECUTE SQLbase;
DEALLOCATE PREPARE SQLbase;
END ;;
this also didn't returns any result set. any one can a sagest a method. thanks in advance