在SQL Server中创建一个函数 getproject()Create Function GetProject(@pro_name varchar(50), @comp_id varchar(50), @flow varchar(50)) RETURN bit AS BEGIN if exists(select 1 from 表1 where 项目名=@pro_name and 公司号 = @comp_id and 流程 = @flow union select 1 from 表2 where 项目名=@pro_name and 公司号 = @comp_id and 流程 = @flow union select 1 from 表3 where 项目名=@pro_name and 公司号 = @comp_id and 流程 = @flow) return 1 else return 0 END
楼上的有错误,修改一下 Create Function GetProject(@pro_name varchar(50), @comp_id varchar(50), @flow varchar(50)) RETURNS bit AS BEGIN DECLARE @rtn BIT if exists(select 1 from 表1 where 项目名=@pro_name and 公司号 = @comp_id and 流程 = @flow union select 1 from 表2 where 项目名=@pro_name and 公司号 = @comp_id and 流程 = @flow union select 1 from 表3 where 项目名=@pro_name and 公司号 = @comp_id and 流程 = @flow) SET @rtn = 1 else SET @rtn = 0 RETURN @rtn END
RETURN bit
AS
BEGIN
if exists(select 1 from 表1 where 项目名=@pro_name and 公司号 = @comp_id and 流程 = @flow
union select 1 from 表2 where 项目名=@pro_name and 公司号 = @comp_id and 流程 = @flow
union select 1 from 表3 where 项目名=@pro_name and 公司号 = @comp_id and 流程 = @flow)
return 1
else
return 0
END
Create Function GetProject(@pro_name varchar(50), @comp_id varchar(50), @flow varchar(50))
RETURNS bit
AS
BEGIN
DECLARE @rtn BIT
if exists(select 1 from 表1 where 项目名=@pro_name and 公司号 = @comp_id and 流程 = @flow
union select 1 from 表2 where 项目名=@pro_name and 公司号 = @comp_id and 流程 = @flow
union select 1 from 表3 where 项目名=@pro_name and 公司号 = @comp_id and 流程 = @flow)
SET @rtn = 1
else
SET @rtn = 0
RETURN @rtn
END
begin
ADOQuery1.SQL.Text := 'SELECT COUNT(*) FROM ( '
+ 'SELECT PrjName, ComID, Flow FROM table1 UNION ALL '
+ 'SELECT PrjName, ComID, Flow FROM table2 UNION ALL '
+ 'SELECT PrjName, ComID, Flow FROM table3 ) A '
+ 'WHERE PrjName = '''+ PrjName +''' AND ComID = '''+ ComID +''' AND Flow = '''+ Flow +''' ';
ADOQuery1.Open;
Result := ADOQuery1.Fields[0].AsInteger > 0;
ADOQuery1.Close;
end;