读书人

急函数里怎么在有条件的提前下返回t

发布时间: 2012-03-20 14:01:11 作者: rapoo

急急急,函数里如何在有条件的提前下,返回table结果集。。。
create function F_A1
(@EMPLOYEE_ID int
)
RETURNS TABLE
RETURN (
select distinct B1,B2 from C1 where D1=@EMPLOYEE_ID
)

如上面的函数,里面没有条件是可以,我想实现下面的有条件的返回table结果集,但是不行。。。
create function F_A1
(@EMPLOYEE_ID int
)
RETURNS TABLE
as
begin
declare @checkOK_COUNT int
select @checkOK_COUNT=count(*) from X
if (@checkOK_COUNT=0)
RETURN (
select distinct B1,B2 from C1 where D1=@EMPLOYEE_ID
)
else
RETURN (
select distinct B1,B2 from M1 where D1=@EMPLOYEE_ID
)
end
GO

还望大师们指点,如何在有条件的提前下,返回table结果集。。。

[解决办法]
勇夺语句表值函数实现

create function func_name
returns @返回变量名
table(列的定义)
as
begin
。。。。。。
end

读书人网 >SQL Server

热点推荐