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