SQL自定义函数调用实例

数据库 SQL Server
下文将以实例的方式为您介绍SQL自定义函数的调用方法,供您参考,如果您对SQL中的自定义函数方面感兴趣的话,不妨一看。

SQL自定义函数是SQL函数中用途最广的函数之一,下面就将为您介绍如何调用SQL自定义函数,供您参考,希望对您有所启迪。

  1. --根据组织,岗位和档案ID返回该用户可见的日报列表  
  2.  
  3. ALTER proc dbo.GetDailyList @orgid int,@postid int,@ArchivesID int  
  4. as  
  5.     declare @a table(orgid int)  
  6.     insert @a select orgid from organize where orgid = @orgid  
  7.     while @@rowcount > 0   --中间有一递归,有点难懂啊  
  8.         insert @a select a.orgid from organize as a inner join @a as b  
  9.         on a.fatherorgid = b.orgid and a.orgid not in(select orgid from @a)  
  10.  
  11.     declare @b table(postid int)  
  12.     insert @b select postid from post where postid = @postid  
  13.     while @@rowcount > 0  
  14.         insert @b select a.postid from post as a inner join @b as b  
  15.         on a.fatherpostid = b.postid and a.postid not in(select postid from @b)  
  16.  
  17. --declare @ArchivesID nvarchar(20)  
  18. --select @ArchivesIDArchivesID=ArchivesID from Users where UserID=@userid  
  19. --print @ArchivesID  
  20.  
  21.  
  22. SELECT a.DailyID, a.TaskTitle,a.AuthorID,b.Name as AuthorName,a.DispathchManID,  
  23.         dbo.GetArchivesNameStr(a.DispathchManID,',') AS DispatchManName,   
  24.         a.AddDate, a.hit,dbo.GetCommentCount(a.DailyID) AS commentcount,  
  25.         'StateStr'=case   
  26.                     when a.StateID=1 then '未执行'  
  27.                     when a.StateID=2 then '执行中'  
  28.                     when a.StateID=3 then '执行完成'  
  29.                 end,  
  30.         'ImportTypeName'=case   
  31.                     when a.ImportTypeID=1 then '普通'  
  32.                     when a.ImportTypeID=2 then '紧急'  
  33.                     when a.ImportTypeID=3 then '非常紧急'  
  34.                 end, dbo.GetArchivesNameStr(FinishManID,',') as FinishManName,  
  35.                 dbo.GetArchivesNameStr(FactDispatchManID,',') as FactDispatchManName  
  36. FROM DailyList a LEFT  JOIN  Archives b on a.AuthorID=b.ArchivesID   
  37. WHERE (a.DailyType = 1) AND   
  38.     b.orgid IN (select orgid from @a) and   
  39.     ','+a.DispathchManID like '%,'+convert(nvarchar,@ArchivesID)+',%' 

 

 

 

【编辑推荐】

SQL自定义函数实例

初级sql select语法

sql server死锁的检测方法

SQL SERVER字段类型的说明

SQL Server安全解析

责任编辑:段燃 来源: 互联网
相关推荐

2010-09-14 16:47:23

SQL自定义函数

2010-09-06 15:41:34

SQL函数存储过程

2013-01-09 17:22:38

Android开发Camera

2010-10-25 16:05:07

oracle自定义函数

2022-04-01 15:59:22

SQLPostgreSQL审计

2010-05-11 13:16:21

Unix awk

2011-06-20 16:03:03

Qt 控件 鼠标

2010-10-20 16:07:48

SQL用户自定义角色

2022-10-09 08:35:06

SQL自定义排序

2010-06-28 11:00:46

SQL Server

2018-03-16 08:41:16

Oracle存储函数

2015-02-12 15:33:43

微信SDK

2024-02-20 08:01:08

SQL注入器MyBatis数据库

2010-07-20 08:48:14

SQL Server

2011-04-19 10:33:16

ASP.NET自定义控

2010-09-09 11:55:36

SQL函数标签

2010-07-09 14:30:56

SQL Server

2009-08-12 14:53:50

C#类型转换函数

2023-10-31 09:10:39

2021-07-15 16:41:21

Swift查询函数
点赞
收藏

51CTO技术栈公众号