IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_get_order_status]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_get_order_status]
GO
CREATE procedure [dbo].[mps_get_order_status](
@bizid int,
@ordid bigint ,
@orderstatus nvarchar(30) output,
@orderkey nvarchar(30) output 
) as
begin
--exec sp_executesql @sql, N'@ws_status nvarchar(30) ,@ws_key varchar(30),@ordid bigint', @orderstatus,@orderkey,@ordid 
declare @sql nvarchar(4000) 
declare @db varchar(50) 
declare @tbid int 

set @sql=''  
select @db=biz_database , @tbid=biz_table from   mps_biztypewhere biz_id=@bizid 
if (@tbid>0) select @db=biz_database , @tbid=biz_id from   mps_biztypewhere biz_id=@tbid 
if (@db>'') set @db=@db+'.dbo.' ;
if (@tbid=0) set @db=@db+'order_'+ltrim(rtrim(str(@bizid))) else set @db=@db+'order_'+ltrim(rtrim(str(@tbid))) 
set @sql = 'select @orderstatus=ord_status , @orderkey=ord_key from  '+@db+'  where ord_id=@ordid ' 
exec sp_executesql @sql, N'@orderstatus nvarchar(30) out ,@orderkey varchar(30) out ,@ordid bigint', @orderstatus out,@orderkey out,@ordid 
set @orderstatus = isnull(@orderstatus,'') 
set @orderkey = isnull(@orderkey,'') 
end