IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_biz_neworder]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_biz_neworder]
GO
create procedure [dbo].[mps_g_biz_neworder](
@cmpid int ,
@bizid int ,
@useruid int 
)
as
begin
set nocount on
declare @tbname varchar(50)
declare @dbname varchar(50)
declare @fkey   varchar(50) 
exec sys_sql_getTableNamePk @cmpid,'biz',@bizid,0,@tbname output,@fkey output ,@dbname output 
select * from mps_biztype where biz_id=@bizid 
select 1 none , 0 none1 where 0=1 
select top 1 * from mps_biztype_comefrom,mps_biztype_comefrom_fieldmap 
where bs_bizid=@bizid  and bs_ord2tag=0 and bs_sord2tag=0 and bs_popwin=0 and bsf_use=0 
and bsf_bsid=bs_id  

select * from mps_biztype_users where bp_bizid=@bizid and bp_cuid=@useruid 

declare @sql nvarchar(3000) 
set @sql = 'select a.* , isnull((select top 1 jb_title+''(''+jb_executor+'')'' from mps_job where jb_crmid=ord_bizid and jb_ordid=ord_id and jb_wsid=0),'''') as jb_title from '+@dbname+@tbname +
' a    where ord_createcuid=@useruid  and ord_finished>=0 and ord_finished<=1 order by ord_date desc ' 
exec sp_executesql @sql, N'@useruid int', @useruid 
set nocount off
end