SQL自定义函数是SQL函数中用途最广的函数之一,下面就将为您介绍如何调用SQL自定义函数,供您参考,希望对您有所启迪 。
- --根据组织,岗位和档案ID返回该用户可见的日报列表
-
- ALTER proc dbo.GetDailyList @orgid int,@postid int,@ArchivesID int
- as
- declare @a table(orgid int)
- insert @a select orgid from organize where orgid = @orgid
- while @@rowcount > 0 --中间有一递归,有点难懂啊
- insert @a select a.orgid from organize as a inner join @a as b
- on a.fatherorgid = b.orgid and a.orgid not in(select orgid from @a)
-
- declare @b table(postid int)
- insert @b select postid from post where postid = @postid
- while @@rowcount > 0
- insert @b select a.postid from post as a inner join @b as b
- on a.fatherpostid = b.postid and a.postid not in(select postid from @b)
-
- --declare @ArchivesID nvarchar(20)
- --select @ArchivesIDArchivesID=ArchivesID from Users where UserID=@userid
- --print @ArchivesID
-
-
- SELECT a.DailyID, a.TaskTitle,a.AuthorID,b.Name as AuthorName,a.DispathchManID,
- dbo.GetArchivesNameStr(a.DispathchManID,,) AS DispatchManName,
- a.AddDate, a.hit,dbo.GetCommentCount(a.DailyID) AS commentcount,
- StateStr=case
- when a.StateID=1 then 未执行
- when a.StateID=2 then 执行中
- when a.StateID=3 then 执行完成
- end,
- ImportTypeName=case
- when a.ImportTypeID=1 then 普通
- when a.ImportTypeID=2 then 紧急
- when a.ImportTypeID=3 then 非常紧急
- end, dbo.GetArchivesNameStr(FinishManID,,) as FinishManName,
- dbo.GetArchivesNameStr(FactDispatchManID,,) as FactDispatchManName
- FROM DailyList a LEFT JOIN Archives b on a.AuthorID=b.ArchivesID
- WHERE (a.DailyType = 1) AND
- b.orgid IN (select orgid from @a) and
- ,+a.DispathchManID like %,+convert(nvarchar,@ArchivesID)+,%