SQL SERVER 2005 .NET UDF
using System;
using System.Text.RegularExpressions;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.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;
}
};
use AdventureWorks
GO
CREATE ASSEMBLY UDF
from 'C:\Users\Roy\Documents\Visual Studio 2008\Projects\UDF\UDF\bin\Release\UDF.dll'
CREATE FUNCTION fCLRExample
(
@Pattern nvarchar(max),
@MatchString nvarchar(max)
)
RETURNS BIT
AS EXTERNAL NAME UDF.UserDefinedFunctions.RegExIsMatch
SELECT ContactID,FirstName,LastName,EmailAddress,Phone
from Person.Contact
WHERE DBO.fCLRExample('[a-zA-Z0-9_\-]+@([a-zA-Z0-9_\-]+\.)+(com|org|edu|mil|net|cn)',EmailAddress)=1
相关文档:
1. 当前系统日期、时间
select getdate()
2. dateadd 在向指定日期加上一段时间的基础上,返回新的 datetime 值
例如:向日期加上2天
&nbs ......
SQL Select语句完整的执行顺序
2009-06-02 15:57
SQL Select语句完整的执行顺序:1、from子句组装来自不同数据源的数据;2、where子句基于指定的条件对记录行进行筛选;3、group by子句将数据划分为多个分组;4、使用聚集函数进行计算;5、使用having子句筛选分组;
以下结论是通过在Sql Server2000上的实验得出的结论, ......
因为要根据很复杂的规则处理用户数据,所以这里用到数据库的游标。平时不怎么用这个,写在这里纯粹为自己备个忘。
--将学籍号重复的放入临时表 tmp_zdsoft_unitive_code(除高中学段外)
drop table tmp_zdsoft_unitive_code;
select s.id ,sch.school_code,sch.school_name,s.student_name,s.unitive_code,s.identity_car ......
问题:假设有张学生成绩表(tb)如下:
姓名 课程 分数
张三 语文 74
张三 数学 83
张三 物理 93
李四 语文 74
李四 数学 84
李四 物理 94
想变成(得到如下结果):
姓名 语文 数学 物理
---- ---- --- ......