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游戏框架libgdx专题】-12-开发工具-图片合成

    TexturePackerGui工具: 1.工具使用: 首先看到texturepacker的界面 界面介绍: New pack:创建项目按钮,单击后输入文件名称,创建文件. Input directo ...

  2. JS获取客户端的窗口大小

    function getClientSize() {    var c = window,    b = document,    a = b.documentElement;    if (c.in ...

  3. cas sso单点登录系列1_cas-client Filter源码解码(转)

    转:http://blog.csdn.net/ae6623/article/details/8841801?utm_source=tuicool&utm_medium=referral /* ...

  4. 何为 pimpl ?

    前言 你是否总因头文件包含冲突而苦恼? 你是否因头文件包含错乱而苦恼? 你是否因封装暴露了数据而苦恼? 你是否因经常改动实现而导致重新编译而苦恼? 在这里, 这些问题都不是问题, 跟随作者, 揭秘pi ...

  5. jquery之bind(),live(),delegate()

    大纲: 1.bind(),live(),delegate()的含义 2.三者基于相同的原理即js的事件冒泡 3.三者相互之间的异同. bind()+live() V.S. delegate():bin ...

  6. C语言笔记(数组地址一些细节)

     一.数组的a+1和&a+1的区别 先看看测试代码: ]={}; printf(" sizeof(data) = %d.\n", sizeof(data)); printf ...

  7. 转:Hprose for php(二)——服务器

    文章来自于:http://blog.csdn.net/half1/article/details/21252879 本文将介绍Hprose for php服务器的更多细节 1.发布服务 Hprose提 ...

  8. 【Android实战开发】3G技术和Android发展简介

    随着移动设备的不断普及和发展,相关软件的开发也越来越受到人们的关注,其中要提及的就是Android开发.本系列博客主要为大家介绍Android的开发,可能会有人问:现在互联网上已经有很多的Androi ...

  9. PCB模擬設計接地的指導原則

    接地無疑是系統設計中最為棘手的問題之一.盡管它的概念相對比較簡單,實施起來卻很復雜,遺憾的是,它沒有一個簡明扼要可以用詳細步驟描述的方法來保證取得良好效果,但如果在某些細節上處理不當,可能會導致令人頭 ...

  10. 【HDOJ】1726 God’s cutter

    简单DP. /* 1726 */ #include <cstdio> #include <cstring> #include <cstdlib> #define M ...