IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[Sys_sql_getDatasource]') AND type = 'P')
DROP PROCEDURE [dbo].[Sys_sql_getDatasource]
GO
create procedure [dbo].[Sys_sql_getDatasource](
@fbiztype varchar(20),--父亲业务类型，biz，emp, dpt,..
@fbizid int,--父亲业务ID
@ftagid int,
@sourcename varchar(20),--数据源名称
@rbiztype varchar(20) output,--数据源对应的业务类型
@rbizid int output,--数据源对应的业务ID
@rtagid int output,
@flindfld varchar(30) output,--父亲的连接字段
@isDetailTable int output--是否明细表
)
as
begin

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
select @rbiztype=null, @flindfld=null, @rbizid=null,@isDetailTable=0,@rtagid=0

select @rbiztype = bizs_sourcetype,@flindfld=bizs_sourcefield,@rbizid=bizs_ctgid 
from mps_biztype_source 
where    bizs_type=@fbiztype
and bizs_bizid=@fbizid and bizs_ord2tag=@ftagid
and  bizs_source=@sourcename
order by bizs_bizid desc 

--明细表
if (@@rowcount=0)
begin
select @rbizid=biz2_bizid,@rbiztype='BIZ',@rtagid=biz2_tag
from mps_biztype2
where biz2_bizid=@fbizid and biz2_caption=@sourcename
if (@@rowcount>0)
select @isDetailTable=1,@flindfld='ord_id'
end

end