What is wrong with this mysql stored procedure.
1. declare - Error(declare in not at this position for this server)
2. both if statements - error(if is not valid at this position)
create procedure autowise.AdjustMapping (IN
Rid bigint,
in pkId bigint
)
begin
declare @unmappedname varchar(50) default '';
if pkid = 0 then
update autowise.custommap set (dbaseto='',table_nameto='',field_nameto='',full_nameto='',noreferance=1) where ident = @rid;
delete from autowise.custommap where parentident=rid;
end if;
if pkid > 0 then
select @unmappedname = (select field_namefrom from autowise.custommap where ident=rid)
update autowise.custommap a,
(select dbase,table_name,Field_name from xmltemplate where ident = pkid ) b
set a.dbaseto = b.dbase,a.table_nameto = b.table_name,a.field_nameto = b.field_name,
noreferance=0,a.Full_nameto = b.full_name
where rid=a.ident;
insert into autowise.custommap (dbasefrom,table_namefrom,field_namefrom,full_nameFrom,Full_nameto,
dbaseto,table_nameto,field_nameto,noreferance,donotuse,parentident)
select 'map',@unmappedname,field_name,concat('map.',@unmappedfieldname,'.',field_name),b.full_name,
b.dbase,b.table_name,b.field_name,0,0,rid
from autowise.xmltemplate a inner join autowise.xmltemplate b on
a.table_name=b.table_name and a.dbase=b.dbase where a.ident =pkid and b.field_name <> b.keyfield;
end if;
end
1. declare - Error(declare in not at this position for this server)
2. both if statements - error(if is not valid at this position)
create procedure autowise.AdjustMapping (IN
Rid bigint,
in pkId bigint
)
begin
declare @unmappedname varchar(50) default '';
if pkid = 0 then
update autowise.custommap set (dbaseto='',table_nameto='',field_nameto='',full_nameto='',noreferance=1) where ident = @rid;
delete from autowise.custommap where parentident=rid;
end if;
if pkid > 0 then
select @unmappedname = (select field_namefrom from autowise.custommap where ident=rid)
update autowise.custommap a,
(select dbase,table_name,Field_name from xmltemplate where ident = pkid ) b
set a.dbaseto = b.dbase,a.table_nameto = b.table_name,a.field_nameto = b.field_name,
noreferance=0,a.Full_nameto = b.full_name
where rid=a.ident;
insert into autowise.custommap (dbasefrom,table_namefrom,field_namefrom,full_nameFrom,Full_nameto,
dbaseto,table_nameto,field_nameto,noreferance,donotuse,parentident)
select 'map',@unmappedname,field_name,concat('map.',@unmappedfieldname,'.',field_name),b.full_name,
b.dbase,b.table_name,b.field_name,0,0,rid
from autowise.xmltemplate a inner join autowise.xmltemplate b on
a.table_name=b.table_name and a.dbase=b.dbase where a.ident =pkid and b.field_name <> b.keyfield;
end if;
end