sqlserver 2000 自定义函数 10

CREATEfunctiondbo.GetPersonTable(@personIDint,@needSelfint)returnstableasreturn(if@ne... CREATE function dbo.GetPersonTable(@personID int, @needSelf int)
returns table as
return(
if @needSelf = 0

SELECT a.* from dbo.v_Person as a
inner join dbo.m_SysUser_Popedom as b on a.i_deptid=b.deptid and b.userid = @personID

else

SELECT a.* from dbo.v_Person as a inner join dbo.m_SysUser_Popedom as b on a.i_deptid=b.deptid and b.userid = @personID
union
select c.* from dbo.v_Person as c where c.personid = @personid
)

报if附近有语法错误 附:dbo.v_Person是视图
展开
 我来答
WHITE_WIN
2013-05-30 · TA获得超过6111个赞
知道大有可为答主
回答量:3759
采纳率:50%
帮助的人:1869万
展开全部
表值函数这样写(需要先定义一个表,然后向定义的表中插入记录即可)
CREATE function dbo.GetPersonTable(@personID int, @needSelf int)
returns @table table(fielda int,fieldb varchar(10))--定义返回表结构,要与你后面查询中字段一致
begin
if @needSelf = 0

insert into @table SELECT a.* from dbo.v_Person as a
inner join dbo.m_SysUser_Popedom as b on a.i_deptid=b.deptid and b.userid = @personID

else
insert into @table
SELECT a.* from dbo.v_Person as a inner join dbo.m_SysUser_Popedom as b on a.i_deptid=b.deptid and b.userid = @personID
union
select c.* from dbo.v_Person as c where c.personid = @personid
return
end
go
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式