日期:2014-05-18  浏览次数:20575 次

急急急,函数里如何在有条件的提前下,返回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