原文地址:http://topic.csdn.net/u/20080803/21/1270777B-A2D6-4323-92D5-CDAA9CF30CF8.html

 

SQL Server提供了大量的函数,
但是在一些常见的如,
字符串拆分,
字符提取,过滤等没有对应的处理,
本帖主要收集一些常见的函数,
整理如下:
------------------------------
http://topic.csdn.net/u/20080306/23/d3c100f2-cda1-4efa-927d-f1f7968884ce.html
/*
功能:拆分字符串.
作者:.....
*/

http://topic.csdn.net/u/20080724/11/dacb530f-62ba-4417-a11a-fe2dee2172b4.html
/*
功能:根据身份证号码取得此CID所在省份
作者:happyflystone
*/

http://topic.csdn.net/u/20080713/00/77925c47-b7fa-4c1b-b307-0328e74a1c09.html
/*
功能:提取数字
功能:提取英文
功能:提取中文
功能:过滤重复字符
功能:过滤重复字符2

作者:wzy_love_sly
*/

MS SQL Server vs Oracle函数
http://topic.csdn.net/u/20071022/09/477d57b8-1127-4159-8975-2055343c624f.html

sql 函数 md5
http://topic.csdn.net/u/20080619/09/4fb22d1b-f88e-487e-8b74-cf394263fc40.html

求sql取字符串的首字母的函数
http://topic.csdn.net/u/20080623/11/22a3f568-d37e-4bf5-9c13-64171066f582.html

形如1,2,3,4,5,6的字符串转换成行
http://topic.csdn.net/u/20080621/08/3397be02-47cd-40c3-9834-600cbb84c0bf.html

小写金额转换成大写
http://topic.csdn.net/u/20080118/11/80ff7847-20d9-45d8-9ed6-79933ced2cf8.html

整数转换成二进制的函数
http://topic.csdn.net/u/20071108/22/1650e0ef-3c14-4710-b2db-075f1e0badf3.html

SQLserver中实现一个函数,能够将10进制转化为36进制
http://topic.csdn.net/u/20070612/16/05e8b690-0818-479d-a34d-ee6258da4027.html

http://blog.csdn.net/roy_88/archive/2007/11/13/1882106.aspx
/*
功能:十进制/十八进制的互转换(此方法应用于所有进制与10进制的转换)
作者:roy_88
*/

http://topic.csdn.net/u/20080715/10/548c6e12-731f-4e54-ac13-d05325068032.html
/*
功能:整数转换成二进制的函数
作者:happyflystone
*/

SQL Server里面有十六进制转化为十进制的函数吗
http://topic.csdn.net/u/20070116/10/0c7d9ec1-acaa-4918-86cd-51516f7f517f.html

SQL2000加密解密函数
http://topic.csdn.net/t/20041202/20/3610469.html

想通过一个函数或sql语句,随机生成任意6个字母组成的字符
http://topic.csdn.net/u/20070627/17/ea906673-9821-46c6-b351-ab98a0b3d2c4.html

求一个sql函数:计算时间差(除周六和周日外)的天数
http://topic.csdn.net/u/20070322/12/2a8d5fcf-2d5b-49e1-b58a-c7277e15ee95.html

Ip算法匹配
http://topic.csdn.net/u/20080711/15/66639249-52d9-40c6-8f5c-131e49c1a6cf.html
http://topic.csdn.net/u/20080801/11/506af00d-b882-41a2-99d9-4dc6927101fd.html

http://blog.csdn.net/dobear_0922/archive/2007/12/18/1947219.aspx
/*
功能:SQL日历函数.
作者:dobear_0922
*/

http://topic.csdn.net/u/20080505/20/d2dffbbe-6d6b-41cf-b29a-41149540eafa.html
/*
功能:两个支持text字段内文字替换的存储过程
作者:realgz
*/

MS SQL Server 2000 中文模糊搜寻存储过程及函数
http://www.cppfans.com/d_vcl_files/mssqlxp_chn.asp


http://topic.csdn.net/t/20050419/10/3948336.html
/*
功能:全角/半角转换 
*/

http://topic.csdn.net/u/20080612/22/c850499f-bce3-4877-82d5-af2357857872.html
/*
功能:合并与拆分
整理者:roy_88
*/

http://topic.csdn.net/u/20080605/11/55c273aa-2206-4ded-b6f6-508a7a755c6a.html
/*
功能:自定义函数,用户可以调用这个函数判断指定的字符串是否符合正则表达式的规则.
作者:ranzj
*/

http://topic.csdn.net/u/20080804/20/09f3d937-d0b9-4892-ab01-fae3f38f0525.html
/*
功能:查找某个字符串第N次出现的位置
作者:.....
*/

 

 

转载 藏经阁第2卷-SQL常用的函数T-SQL: 15 个与日期时间相关的精典语句函数
转载 藏经阁第2卷-SQL常用的函数
转载 藏经阁第2卷-SQL常用的函数T
-SQL: 15 个与日期时间相关的自定义函数(UDF),周日作为周的最后一天,均不受 @@DateFirst、语言版本影响
转载 藏经阁第2卷-SQL常用的函数都是从老文章里收集或提炼出来的!
转载 藏经阁第2卷-SQL常用的函数提示:
转载 藏经阁第2卷-SQL常用的函数(
@@Datefirst + datepart(weekday,@Date)) % 7 判断周几是最保险的! 与 @@DateFirst 无关,与语言版本无关
转载 藏经阁第2卷-SQL常用的函数
@@DateFirst 可能会导致 datepart(weekday,@Date) 不一样!
转载 藏经阁第2卷-SQL常用的函数无论 
@@DateFirst 等于几,无论是什么语言版本的 SQL Server 下面永远恒成立!
转载 藏经阁第2卷-SQL常用的函数(
@@Datefirst + datepart(weekday,@Date)): 2345601 分别代表 周一 到 周日
转载 藏经阁第2卷-SQL常用的函数
-- */
转载 藏经阁第2卷-SQL常用的函数
create function udf_GetAge(@StartDate datetime,@EndDate datetime)
转载 藏经阁第2卷-SQL常用的函数
returns integer
转载 藏经阁第2卷-SQL常用的函数
-- 返回精确年龄 select dbo.udf_GetAge('1949-10-01',getdate())
转载 藏经阁第2卷-SQL常用的函数
begin
转载 藏经阁第2卷-SQL常用的函数
return datediff(year,@StartDate,@EndDate)
转载 藏经阁第2卷-SQL常用的函数       
- case when datediff(day,dateadd(year,datediff(year,@StartDate,@EndDate),@StartDate),@EndDate>= 0
转载 藏经阁第2卷-SQL常用的函数                   
then 0
转载 藏经阁第2卷-SQL常用的函数              
else
转载 藏经阁第2卷-SQL常用的函数                   
1
转载 藏经阁第2卷-SQL常用的函数         
end
转载 藏经阁第2卷-SQL常用的函数
end
转载 藏经阁第2卷-SQL常用的函数
go
转载 藏经阁第2卷-SQL常用的函数
转载 藏经阁第2卷-SQL常用的函数
create function udf_DaysOfYearByDate(@Date datetime)
转载 藏经阁第2卷-SQL常用的函数
RETURNS integer
转载 藏经阁第2卷-SQL常用的函数
-- 返回年的天数 可判断 平(365)、润(366) 年
转载 藏经阁第2卷-SQL常用的函数
begin
转载 藏经阁第2卷-SQL常用的函数
return datediff(day,dateadd(year,datediff(year,0,@Date),0),dateadd(year,datediff(year,0,@Date )+1,0))
转载 藏经阁第2卷-SQL常用的函数
end
转载 藏经阁第2卷-SQL常用的函数
go
转载 藏经阁第2卷-SQL常用的函数
create function udf_DaysOfYear(@Year integer)
转载 藏经阁第2卷-SQL常用的函数
RETURNS integer
转载 藏经阁第2卷-SQL常用的函数
-- 返回年的天数 可判断 平(365)、润(366) 年
转载 藏经阁第2卷-SQL常用的函数
begin
转载 藏经阁第2卷-SQL常用的函数
return datediff(day,dateadd(year,@year - year(0),0),dateadd(year,@year - year(0+ 1,0))
转载 藏经阁第2卷-SQL常用的函数
end
转载 藏经阁第2卷-SQL常用的函数
go
转载 藏经阁第2卷-SQL常用的函数
转载 藏经阁第2卷-SQL常用的函数
create function udf_HalfDay(@Date datetime)
转载 藏经阁第2卷-SQL常用的函数
returns datetime
转载 藏经阁第2卷-SQL常用的函数
-- 返回 @Date 是 上午 返回 @Date 的零点,@Date 是 下午 返回 @Date 的十二点
转载 藏经阁第2卷-SQL常用的函数
as
转载 藏经阁第2卷-SQL常用的函数
begin
转载 藏经阁第2卷-SQL常用的函数
return case when datepart(hour,@Date
转载 藏经阁第2卷-SQL常用的函数
go
转载 藏经阁第2卷-SQL常用的函数
create function udf_WeekDiff(@StartDate datetime,@EndDate datetime)
转载 藏经阁第2卷-SQL常用的函数
returns integer
转载 藏经阁第2卷-SQL常用的函数
-- 返回 [@StartDate , @EndDate] 之间周数 周日是当周的最后一天
转载 藏经阁第2卷-SQL常用的函数
begin
转载 藏经阁第2卷-SQL常用的函数
return datediff(week,@StartDate,@EndDate-- + 1
转载 藏经阁第2卷-SQL常用的函数
       + case when (@@Datefirst + datepart(weekday,@StartDate)) % 7 = 1
转载 藏经阁第2卷-SQL常用的函数                   
then 1
转载 藏经阁第2卷-SQL常用的函数              
else
转载 藏经阁第2卷-SQL常用的函数                   
0
转载 藏经阁第2卷-SQL常用的函数         
end
转载 藏经阁第2卷-SQL常用的函数       
- case when (@@Datefirst + datepart(weekday,@EndDate)) % 7 = 1
转载 藏经阁第2卷-SQL常用的函数                   
then 1
转载 藏经阁第2卷-SQL常用的函数              
else 0
转载 藏经阁第2卷-SQL常用的函数         
end
转载 藏经阁第2卷-SQL常用的函数
end
转载 藏经阁第2卷-SQL常用的函数
go
转载 藏经阁第2卷-SQL常用的函数
转载 藏经阁第2卷-SQL常用的函数
create function udf_WeekOfMonth(@Date datetime)
转载 藏经阁第2卷-SQL常用的函数
-- 返回 @Date 是所在月的第几周 周日是当周的最后一天
转载 藏经阁第2卷-SQL常用的函数
returns integer
转载 藏经阁第2卷-SQL常用的函数
as
转载 藏经阁第2卷-SQL常用的函数
begin
转载 藏经阁第2卷-SQL常用的函数
return datediff(week
转载 藏经阁第2卷-SQL常用的函数                ,
case when (@@Datefirst + datepart(weekday,dateadd(month,datediff(month,0,@Date),0))) % 7 = 1
转载 藏经阁第2卷-SQL常用的函数                           
then dateadd(month,datediff(month,0,@Date),0- 1
转载 藏经阁第2卷-SQL常用的函数                      
else
转载 藏经阁第2卷-SQL常用的函数                           
dateadd(month,datediff(month,0,@Date),0)
转载 藏经阁第2卷-SQL常用的函数                      
end
转载 藏经阁第2卷-SQL常用的函数                ,
case when (@@Datefirst + datepart(weekday,@Date)) % 7 = 1
转载 藏经阁第2卷-SQL常用的函数                           
then @Date-1
转载 藏经阁第2卷-SQL常用的函数                      
else @Date
转载 藏经阁第2卷-SQL常用的函数                 
end
转载 藏经阁第2卷-SQL常用的函数               ) 
+ 1
转载 藏经阁第2卷-SQL常用的函数
end
转载 藏经阁第2卷-SQL常用的函数
go
转载 藏经阁第2卷-SQL常用的函数
转载 藏经阁第2卷-SQL常用的函数
create function udf_WeekOfQuarter(@Date datetime)
转载 藏经阁第2卷-SQL常用的函数
-- 返回 @Date 是所在季度的第几周 周日是当周的最后一天
转载 藏经阁第2卷-SQL常用的函数
returns int
转载 藏经阁第2卷-SQL常用的函数
as
转载 藏经阁第2卷-SQL常用的函数
begin
转载 藏经阁第2卷-SQL常用的函数
return datediff(week
转载 藏经阁第2卷-SQL常用的函数                ,
case when (@@Datefirst + datepart(weekday,dateadd(Quarter,datediff(Quarter,0,@Date),0))) % 7 = 1
转载 藏经阁第2卷-SQL常用的函数                           
then dateadd(Quarter,datediff(Quarter,0,@Date),0- 1
转载 藏经阁第2卷-SQL常用的函数                      
else
转载 藏经阁第2卷-SQL常用的函数                           
dateadd(Quarter,datediff(Quarter,0,@Date),0)
转载 藏经阁第2卷-SQL常用的函数                 
end
转载 藏经阁第2卷-SQL常用的函数                ,
case when (@@Datefirst + datepart(weekday,@Date)) % 7 = 1
转载 藏经阁第2卷-SQL常用的函数                           
then @Date - 1
转载 藏经阁第2卷-SQL常用的函数                      
else
转载 藏经阁第2卷-SQL常用的函数                           
@Date
转载 藏经阁第2卷-SQL常用的函数                 
end
转载 藏经阁第2卷-SQL常用的函数               ) 
+ 1
转载 藏经阁第2卷-SQL常用的函数
end
转载 藏经阁第2卷-SQL常用的函数
go
转载 藏经阁第2卷-SQL常用的函数
转载 藏经阁第2卷-SQL常用的函数
create function udf_WeekOfYear(@Date datetime)
转载 藏经阁第2卷-SQL常用的函数
-- 返回 @Date 是所在年的第几周 周日是当周的最后一天
转载 藏经阁第2卷-SQL常用的函数
returns int
转载 藏经阁第2卷-SQL常用的函数
as
转载 藏经阁第2卷-SQL常用的函数
begin
转载 藏经阁第2卷-SQL常用的函数
return datediff(week
转载 藏经阁第2卷-SQL常用的函数                ,
case when (@@Datefirst + datepart(weekday,dateadd(day,0,datediff(day,0,dateadd(year,datediff(year,0,@Date),0))))) % 7 = 1
转载 藏经阁第2卷-SQL常用的函数                           
then dateadd(day,-1,dateadd(day,0,datediff(day,0,dateadd(year,datediff(year,0,@Date),0))))
转载 藏经阁第2卷-SQL常用的函数                      
else
转载 藏经阁第2卷-SQL常用的函数                           
dateadd(day,0,datediff(day,0,dateadd(year,datediff(year,0,@Date),0))) --date 所在年的第一天 即: 一月一号
转载 藏经阁第2卷-SQL常用的函数
                 end
转载 藏经阁第2卷-SQL常用的函数                ,
case when (@@Datefirst + datepart(weekday,@Date)) % 7 = 1
转载 藏经阁第2卷-SQL常用的函数                           
then dateadd(day,-1,@Date)
转载 藏经阁第2卷-SQL常用的函数                      
else
转载 藏经阁第2卷-SQL常用的函数                           
@Date
转载 藏经阁第2卷-SQL常用的函数                 
end
转载 藏经阁第2卷-SQL常用的函数               ) 
+ 1
转载 藏经阁第2卷-SQL常用的函数
end
转载 藏经阁第2卷-SQL常用的函数
go
转载 藏经阁第2卷-SQL常用的函数
转载 藏经阁第2卷-SQL常用的函数
create function udf_WeekDay(@ int,@Date datetime)
转载 藏经阁第2卷-SQL常用的函数
returns datetime
转载 藏经阁第2卷-SQL常用的函数
-- 返回 @Date 映射到 所在周的其他天 周日是当周的最后一天
转载 藏经阁第2卷-SQL常用的函数
begin
---------------------------------------

相关文章: