mrRobot
mrRobot

Reputation: 21

MySql Code: 1241 operand should contain 1 column(s)

I found different topics here in stackoverflow related to Mysql Error: 1241. And as I read all the topics, they have some common issues related on their sub-queries. But my problem is different.

PROBLEM: - MySql Code: 1241 operand should contain 1 column(s)

FROM - One of my Stored Procedure with prepared statements

NOTE - My select statement has no sub-query as well as my update statement.

SCREEN SHOT - ACTUAL SS

STORED PROCEDURE CODE

CREATE PROCEDURE CancelRow_EM(IN tbl_name VARCHAR(25), IN rowindex FLOAT, OUT flagresult TINYINT, OUT msgresult VARCHAR(300))

 BEGIN
 START TRANSACTION;
IF tbl_name="emps_tbl" THEN
    SET @PrimaryCol="EMPS_ID";
    SET @RefCol="OBR NO.";

ELSEIF tbl_name="emmooe_tbl" THEN
    SET @PrimaryCol="EMMOOE_ID";
    SET @RefCol="PR NO.";

ELSEIF tbl_name="emco_tbl" THEN
    SET @PrimaryCol="EMCO_ID";
    SET @RefCol="PR NO.";

END IF;

SET @select1=CONCAT("SELECT `LINK_ID`,`",@RefCol,"` INTO @li,@Ref FROM `",tbl_name,"` WHERE ROUND(`EMPS_ID`,3)=",rowindex);
PREPARE stmtselect1 FROM @select1;
EXECUTE stmtselect1;
DEALLOCATE PREPARE stmtselect1; 

If @li IS NOT NULL THEN
    SET flagresult=0;
    SET msgresult="Cancellation of record was stopped. Reason: Earmark record was already utilize.";

ELSE
    SET @update1=CONCAT("UPDATE `",tbl_name,"` SET `CANCEL_STATUS`=1 WHERE ROUND(`",@PrimaryCol,"`,3)=",rowindex," AND `",@RefCol,"`='",@Ref,"'");
    PREPARE stmtupdate1 FROM @update1;
    EXECUTE stmtupdate1;

    SELECT row_count() INTO @RowsAffected1;
    DEALLOCATE PREPARE stmtupdate1;

    IF @RowsAffected1>0 THEN
        SET flagresult=1;
        SET msgresult=("No. of affected rows(s):",@RowsAffected1,", from modification process.");
        COMMIT;
    ELSE
        SET flagresult=0;
        SET msgresult=("There are no affected row(s) from modification process.");
        ROLLBACK;   
    END IF;
END IF;

END

Upvotes: 1

Views: 652

Answers (2)

Mayur Kothari
Mayur Kothari

Reputation: 21

Syntax error, remove the ( ) from select.

Upvotes: 1

Bill Karwin
Bill Karwin

Reputation: 562310

You can't assign a tuple to a single variable.

This:

SET msgresult=("No. of affected rows(s):",@RowsAffected1,", from modification process.");

Should be:

SET msgresult=CONCAT("No. of affected rows(s):",@RowsAffected1,", from modification process.");

Upvotes: 1

Related Questions