mysql - Error when using case with variables -


hey guys facing problem when use variable case in mysql.

the code have used is

declare vsite varchar(20); set vsite = case   when id > 0 'sdfsdf'   else 'asd' end name  customers; 

when run code throws me error

you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'declare vsite varchar(20)' @ line 1: declare vsite varchar(20) 

can point me going wrong..thanks valuable help

you need declare variables inside begin end block.

here simple example of stored procedure

delimiter // create procedure blah(in customer_id int,out vsite varchar(20)) begin  select case when id > 0 'blah' else 'mah' end vsite customers id=customer_id; end// delimiter ;  call blah(3,@somevar); select @somevar; 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -