scheduler events in mysql using if conditions -


i have written below query

  create event test_event_03   on schedule every 1 minute   starts current_timestamp   ends current_timestamp + interval 1 hour     declare cnt1 bigint   select count(*) cnt1, d.invoice_date invoice_date1 depot_sales__c d,  advance_payment_request__c a, supplier_payment__c s d.supplier_code=a.supplier , d.supplier_code=s.supplier , s.supplier=80    if cnt1=0    select count(*) depot_sales__c d     end if; 

i getting below error

 error code : 1064  have error in sql syntax; check manual corresponds mysql server version right syntax use near 'declare cnt1 bigint   select count(*) cnt1, d.invoice_date invoice_date1 ' @ line 8    have error in sql syntax; check manual corresponds mysql server version right syntax use near  'if cnt1=0 then' @ line 10 

why getting error?

the problem can use declare statement inside begin..end block, , @ beginning of block. see mysql documentation @ http://dev.mysql.com/doc/refman/5.0/en/declare.html. you'll need wrap statement in begin...end block. , think you'll need change delimiter can more 1 statement. so, end being like:

  delimiter |   create event test_event_03   on schedule every 1 minute   starts current_timestamp   ends current_timestamp + interval 1 hour     begin   declare cnt1 bigint;   select count(*) cnt1, d.invoice_date invoice_date1 depot_sales__c d,  advance_payment_request__c a, supplier_payment__c s d.supplier_code=a.supplier , d.supplier_code=s.supplier , s.supplier=80;    if cnt1=0    select count(*) depot_sales__c d;     end if;  end |  delimiter ; 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -