SQL自定義函數(shù)調(diào)用實例
作者:佚名
下文將以實例的方式為您介紹SQL自定義函數(shù)的調(diào)用方法,供您參考,如果您對SQL中的自定義函數(shù)方面感興趣的話,不妨一看。
SQL自定義函數(shù)是SQL函數(shù)中用途最廣的函數(shù)之一,下面就將為您介紹如何調(diào)用SQL自定義函數(shù),供您參考,希望對您有所啟迪。
- --根據(jù)組織,崗位和檔案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 '未執(zhí)行'
- when a.StateID=2 then '執(zhí)行中'
- when a.StateID=3 then '執(zhí)行完成'
- 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)+',%'
【編輯推薦】
責任編輯:段燃
來源:
互聯(lián)網(wǎng)