IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_order_byno]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_order_byno]
GO
create procedure [dbo].[mps_g_order_byno]
(
@cmpid int ,
@bizid int , 
@ordno nvarchar(50) 
) as 
begin
set nocount on 
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED 
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  
declare @sql nvarchar(4000) 
set @sql = 'select * from '+@dbname+@tbname+' where ord_cmpid='+CONVERT(varchar(10),@cmpid)+' and ord_no='''+@ordno+''' ' 
execute(@sql) 

set @sql = 'select a.* from mps_job a, '+@dbname+@tbname+' where ord_cmpid='+CONVERT(varchar(10),@cmpid)+' and ord_no='''+@ordno+''' and jb_crmid=ord_bizid and jb_ordid=ord_id ' +
' and jb_wsid>0 and jb_back=1 and jb_isauto=1 and jb_enabled=0 and jb_confirm=0    order by jb_id ' 
execute(@sql) 
set nocount off 
end