IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[sys_sql_getFldInfo]') AND type = 'P')
DROP PROCEDURE [dbo].[sys_sql_getFldInfo]
GO
 --@cmpid int, @biztype  @bizid  @tagid  @srcname 
 --@rfldid int output, @rfldname output,@rdatatype @rsize  @rprec 
 create procedure [dbo].[sys_sql_getFldInfo](
 @cmpid int,--公司ID
 @biztype varchar(20),--业务类型
 @bizid int,--业务ID
 @tagid int,
 @srcname varchar(30),--字段名称（中英文都可以）
 @rfldid int output,
 @rfldname varchar(30) output,--对应字段名称
 @rdatatype varchar(30) output,--数据类型
 @rsize int output,--字段长度
 @rprec int output--字段精度
 )
 as
 begin
 select @rfldname = null,@rdatatype=null,@rsize=50,@rprec=2
 
 select @rfldname=fldi_fieldname,@rdatatype=fldi_datatype,@rsize=fldi_size,@rprec=fldi_decimal,
 @rfldid=fldi_id
from mps_fieldinfo 
where  fldi_cmpid=@cmpid and fldi_tbtype=@biztype
and fldi_tbid=@bizid and fldi_ord2tag=@tagid
and (fldi_fieldname=@srcname or fldi_fieldcaption=@srcname)

if (@rfldname is null or len(@rfldname)<2)
begin
if (@srcname='ord_id' or @srcname='ord2_id' 
   or @srcname='ord_ftype' or @srcname='ord_fbizid' 
   or @srcname='ord_ford2tag' or @srcname='ord_fordid' 
   or @srcname='ord_ford2id'
   or @srcname='ord_rtype' or @srcname='ord_rbizid' 
   or @srcname='ord_rord2tag' or @srcname='ord_rordid'
   or @srcname='ord_rord2id')
    
  set @rfldname=@srcname
end
 end