IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_cart2order]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_cart2order]
GO
create proc [dbo].[mps_cart2order](
@cmpid int ,
@branchid int ,
@userdpid int , 
@useruid int , 
@bizid int ,
@malltype nvarchar(30) 
) as
begin
set nocount on
declare @sql nvarchar(4000) 
declare status1 cursor LOCAL FORWARD_ONLY READ_ONLY for
  select distinct sp_cuid  from mps_salecart  with(nolock) , mps_saleprds with(nolock)  
  where ct_cuid=@useruid and ct_spid=sp_id and sp_type=@malltype and ct_amount>0  
  open status1
  declare @spcuid int 
  declare @param1 nvarchar(1000) 
  declare @newordid bigint 
  
  declare @t table(bizid int , ordid bigint) 
  
  FETCH NEXT FROM status1 INTO @spcuid 
  WHILE (@@FETCH_STATUS = 0)
  BEGIN
  set @param1 = convert(varchar(100),@spcuid) 
   set @sql = 'exec  order_'+CONVERT(varchar(20),@bizid)+'_newbiz @cmpid , @branchid , @userdpid , 0 , @useruid , 0 , @bizid , '''',0,'''',0,0,2,@param1,'''','''',@newordid output ' 
exec sp_executesql @sql, N'@cmpid int ,@branchid int ,@userdpid int , @useruid int , @bizid int,@param1 nvarchar(1000),@newordid bigint out', 
@cmpid , @branchid , @userdpid , @useruid , @bizid , @param1, @newordid out 
insert into @t(bizid,ordid) values(@bizid , @newordid) 
   FETCH NEXT FROM status1 INTO @spcuid 
  END
  CLOSE status1
DEALLOCATE status1 

select * from @t 
set nocount off 
end