存储过程的作用是产生单据号码,如下:
create procedure p_ins_no
 (OprSign varchar(2),DbSign varchar(2),InsName varchar(40),OUT BillId varchar(16))
begin
declare InsNumber varchar(8);
declare InsSign varchar(2);
select  Ins_Number, Ins_Id into InsNumber,InsSign  from mobile.autoins where Ins_Name =InsName ;
set InsNumber = lpad(CAST(InsNumber+1 AS char),8,'0');
set BillId=concat(InsSign, InsNumber,OprSign,DbSign);
update autoins set Ins_Number = InsNumber where Ins_Name = InsName;end;
想在select查询中为每行添加一个单据号码插入到一个新表中,实现的效果为:
insert into table1(xxx,xxx) select call p_ins_no(xx,xx,xx,xx),其它列 from table2 where xxxxx.....

解决方案 »

  1.   

    存储过程的返回值获取方法: call p_ins_no(@xx);
    然后在插入时用insert into table1(xxx,xxx) select @xx,其它列 from table2 where xxxxx.....也就是说要先执行存储过程。
      

  2.   

    table2有多条记录,每行的单据号需要唯一,那有咋办呢?MS SQL中可以这样:INSERT INTO table_name EXEC procedure_name @parameters_value。
    MySql中有没类似的方法
      

  3.   

    每执行一次call p_ins_no(@xx);返回一个确定的值,再把这个值插入到新表去。
      

  4.   

    在select中不能使用过程,只能用表值函数...
      

  5.   

    算了,改成前台录入数据时call p_ins_no,并暂存到前台,然后一次插入