C# 代码

using Microsoft.SqlServer.Server;
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; public partial class UserDefinedFunctions
{
public static SqlString ExampleUDF()
{
return new SqlString("Hello");
}
[SqlFunction(IsDeterministic = true, IsPrecise = true)]
public static bool RegExIsMatch(string pattern, string matchString)
{
Regex reg = new Regex(pattern.TrimEnd(null));
return reg.Match(matchString.TrimEnd(null)).Success;
}
}

SQL SERVER 代码

加载程序集

USE InvestorRelations
CREATE ASSEMBLY ExampleUDF
FROM 'E:\学习\SessionTest\TestKZCCGC\bin\Debug\TestKZCCGC.dll'

创建函数

CREATE FUNCTION ExampleUDFTwo()
RETURNS nvarchar(1000)
AS EXTERNAL NAME ExampleUDF.UserDefinedFunctions.ExampleUDF;

  

表值函数:

C#代码

using Microsoft.SqlServer.Server;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; public partial class UserDefinedFunctions
{
[SqlFunction(FillRowMethodName = "FillRow")]
public static IEnumerable DirectoryList(string sRootDir, string sWildCard, bool bIncludeSubDirs)
{
ArrayList aFileArray = new ArrayList();
DirectorySearch(sRootDir, sWildCard, bIncludeSubDirs, aFileArray);
return aFileArray;
}
private static void DirectorySearch(string directory, string sWildCard, bool bIncludeSubDirs, ArrayList aFileArray)
{
GetFiles(directory, sWildCard, aFileArray);
if (bIncludeSubDirs)
{
foreach (string d in Directory.GetDirectories(directory))
{
DirectorySearch(d, sWildCard, bIncludeSubDirs, aFileArray);
}
}
}
private static void GetFiles(string d, string sWildCard, ArrayList aFileArray)
{
foreach (string f in Directory.GetFiles(d, sWildCard))
{
FileInfo fi = new FileInfo(f);
object[] column = new object[2];
column[0] = fi.FullName;
column[1] = fi.LastWriteTime;
aFileArray.Add(column);
}
}
private static void FillRow(object obj, out string filename, out DateTime date)
{
object[] row = (object[])obj;
filename = (string)row[0];
date = (DateTime)row[1];
}
}

  SQL SERVER 代码

ALTER DATABASE InvestorRelations
SET TRUSTWORTHY ON; USE InvestorRelations CREATE ASSEMBLY fExampleTVF
FROM 'E:\学习\SessionTest\TestKZCCGC\bin\Debug\TestKZCCGC.dll'
WITH PERMISSION_SET=EXTERNAL_ACCESS CREATE FUNCTION fTVFExample(
@RootDir nvarchar(max),
@WildCard nvarchar(max),
@IncludeSubDirs bit
)
RETURNS TABLE (
FileName nvarchar(max),
LastWriteTime datetime
)
AS EXTERNAL NAME fExampleTVF.UserDefinedFunctions.DirectoryList SELECT FILENAME,LASTWRITETIME
FROM dbo.fTVFExample('E:\学习','*.ppt',0)

  

sql server 扩展存储过程的更多相关文章

  1. SQL Server中存储过程 比 直接运行SQL语句慢的原因

    问题是存储过程的Parameter sniffing     在很多的资料中都描述说SQLSERVER的存储过程较普通的SQL语句有以下优点: 1. 存储过程只在创造时进行编译即可,以后每次执行存储过 ...

  2. SQL Server 扩展事件(Extented Events)从入门到进阶(1)——从SQL Trace到Extented Events

    由于工作需要,决定深入研究SQL Server的扩展事件(Extended Events/xEvents),经过资料搜索,发现国外大牛的系列文章,作为“学习”阶段,我先翻译这系列文章,后续在工作中的心 ...

  3. SQL Server中存储过程比直接运行SQL语句慢的原因

    原文:SQL Server中存储过程比直接运行SQL语句慢的原因 在很多的资料中都描述说SQLSERVER的存储过程较普通的SQL语句有以下优点: 1.       存储过程只在创造时进行编译即可,以 ...

  4. SQL Server 扩展事件(Extented Events)从入门到进阶(4)——扩展事件引擎——基本概念

    本文属于 SQL Server 扩展事件(Extented Events)从入门到进阶 系列 在第一二节中,我们创建了一些简单的.类似典型SQL Trace的扩展事件会话.在此过程中,介绍了很多扩展事 ...

  5. SQL Server 扩展事件(Extented Events)从入门到进阶(3)——通过界面操作Extented Event

    本文属于 SQL Server扩展事件(Extended Events)从入门到进阶 系列 对于接纳扩展事件,其中一个最大的障碍就是要对XML和XQuery有一定的了解以便分析数据.我们可以使用T-S ...

  6. SQL Server 扩展事件(Extented Events)从入门到进阶(2)——在GUI中创建基础扩展事件

    本文属于 SQL Server 扩展事件(Extented Events)从入门到进阶 系列 第一篇文章中提到了如何在Profiler中创建跟踪(trace),并以服务器端(server-side)跟 ...

  7. sql server系统存储过程大全

    关键词:sql server系统存储过程,mssql系统存储过程 xp_cmdshell --*执行DOS各种命令,结果以文本行返回. xp_fixeddrives --*查询各磁盘/分区可用空间 x ...

  8. 在sql server中建存储过程,如果需要参数是一个可变集合怎么处理?

    在sql server中建存储过程,如果需要参数是一个可变集合的处理 原存储过程,@objectIds 为可变参数,比如 110,98,99 ALTER PROC [dbo].[Proc_totalS ...

  9. 在易语言中调用MS SQL SERVER数据库存储过程方法总结

    Microsoft SQL SERVER 数据库存储过程,根据其输入输出数据,笼统的可以分为以下几种情况或其组合:无输入,有一个或多个输入参数,无输出,直接返回(return)一个值,通过output ...

随机推荐

  1. 【转】Java 读写Properties配置文件

    [转]Java 读写Properties配置文件 1.Properties类与Properties配置文件 Properties类继承自Hashtable类并且实现了Map接口,也是使用一种键值对的形 ...

  2. 一个类实现多个接口的demo

    //A接口 interface A{ public int getA(); } //B接口 interface B{ public int getB(); } //实现了某个接口必须实现其全部的方法 ...

  3. java.lang.ClassCastException

    是指类型转换出错 当前者的域小于后者的时候出现 譬如说:前者A是子类的对象,而后者B是父类的对象 若使用A = B;就会抛出java.lang.ClassCastException List<C ...

  4. 通过ip地址获取当前地理位置

    1.  使用接口的方式: 这种方式是相对稳定,而且提供的数据相对稳定,提供接口的地方很多,大家可以参照 http://www.hujuntao.com/api/the-ip-address-api-a ...

  5. this,super关键字的使用

    this关键字 1.this是对象的别名,是当前类的实例引用 2.在类的成员方法内部使用,代替当前类的实例.在Java中,本质上是指针,相当于C++中的指针概念.如果方法中的成员在调用前没有操作实例名 ...

  6. SQLServer2008收缩数据库日志

    -- Set to SIMPLE mode ALTER DATABASE [DATABASE_NAME] SET RECOVERY SIMPLE; -- Shrink the db ); -- Set ...

  7. Linux 抓取网站命令

    wget -m -e robots=off -U "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.6) Gecko/200 ...

  8. [转] 与调试器共舞 - LLDB 的华尔兹

    你是否曾经苦恼于理解你的代码,而去尝试打印一个变量的值? NSLog(@"%@", whatIsInsideThisThing); 或者跳过一个函数调用来简化程序的行为? NSNu ...

  9. Xcode7设置生成DSYM出现大量警告

    看图,设置成这样就会出现大量的警告,解决方法如下: 将debug information format 更改为:DWARF即可

  10. 跟我学android-Notification

    Notification 可以理解为通知的意思,会出现在通知栏,比如来了一条短信 使用 Notification 有以下3个步骤: 1. 创建 NotificationManager的对象 2.为No ...