sql - Subquery returns more than one row in mysql -


can 1 tell what's going wrong routine have written

routine ddl:

delimiter $$  create definer=`root`@`%` procedure `uspemployeebankdataupdate`(_empid int,                 _payeename varchar(20),                 _bankroutingnumber varchar(9),                 _banktypeid varchar(5),                 _accounttype varchar(2),                 _bankaccount int,       _amount double,                 _comments varchar(50),                 _address1 varchar(30),                 _address2 varchar(30),                 _zipcode decimal(9,0),                 _city varchar(25),                 _statename varchar(30),                 _country varchar(20),       _bankaccounttype varchar(30),       _enddate datetime) begin  declare p_ecount int;  declare _startdate date;  set _startdate=(select date(startdate) tblemployeebankdata             empid=_empid ,            enddate='9999-12-31');     set p_ecount=(select count(1) tblemployeebankdata     payeename=_payeename ,      bankroutingnumber=_bankroutingnumber ,  banktypeid=_banktypeid , accounttype=_accounttype , bankaccount=_bankaccount , amount=_amount ,  comments=_comments , address1=_address1 ,  address2=_address2 ,  zipcode=_zipcode ,  city=_city , statename=_statename ,  country=_country ,  bankaccounttype=_bankaccounttype ,  enddate='9999-12-31');  if  p_ecount=0 , _startdate<curdate()             begin             update tblemployeebankdata set enddate=_enddate     empid=_empid , enddate="9999-12-31";           end;    end if;    end 

this sample code of passing

  m_ocmd.parameters.addwithvalue("_empid", empid);             m_ocmd.parameters.addwithvalue("_payeename", payeename);             m_ocmd.parameters.addwithvalue("_banktypeid", banktypeid);             m_ocmd.parameters.addwithvalue("_accounttype", accounttype);             m_ocmd.parameters.addwithvalue("_bankroutingnumber", bankroutingnumber);             m_ocmd.parameters.addwithvalue("_bankaccounttype", bankaccounttype);             m_ocmd.parameters.addwithvalue("_bankaccount", bankaccount);             m_ocmd.parameters.addwithvalue("_amount", amount);             m_ocmd.parameters.addwithvalue("_comments", comments);             m_ocmd.parameters.addwithvalue("_address1", address1);             m_ocmd.parameters.addwithvalue("_address2", address2);             m_ocmd.parameters.addwithvalue("_zipcode", zipcode);             m_ocmd.parameters.addwithvalue("_city", city);             m_ocmd.parameters.addwithvalue("_statename", statename);             m_ocmd.parameters.addwithvalue("_country", country);             m_ocmd.parameters.addwithvalue("_enddate", enddate); 

the error here

set _startdate=(select date(startdate) tblemployeebankdata             empid=_empid ,            enddate='9999-12-31'); 

if condition empid=_empid , enddate='9999-12-31' results in more 1 record, fails. use limit , order choose 1 particular record (startdate), e.g.

set _startdate=(select date(startdate) tblemployeebankdata             empid=_empid ,            enddate='9999-12-31'            order startdate desc            limit 1); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -