日期:2011-01-25 23:11:00 来源:本站整理
<b>SQL自定义函数调用实例</b>[MSSQL防范]
本文“<b>SQL自定义函数调用实例</b>[MSSQL防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
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)+',%'
以上是“<b>SQL自定义函数调用实例</b>[MSSQL防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论