IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[checkfield]') AND type = 'FN')
DROP FUNCTION [dbo].[checkfield]
GO
CREATE function [dbo].[checkfield](
@cmpid int , 
@tablename varchar(100),
@fieldname  varchar(100)
) 
RETURNS int
begin
declare @re int 
if (exists (select 1 from mps_fieldinfo with(nolock) where fldi_cmpid=@cmpid and fldi_tbname=@tablename and fldi_fieldname=@fieldname)) 
set @re = 0 else set @re = 1 
return @re
end