根据日期返回星座
来源:互联网 发布:天马网络分销平台 编辑:程序博客网 时间:2024/04/29 22:05
go
--创建函数(CSDN fredrickhu(小F)提供)
create function udf_GetStar (@ datetime)
RETURNS varchar(100)
-- 返回日期所属星座
BEGIN
RETURN
(
select max(star)
from
(
select '魔羯座' as star,1 as [month],1 as [day]
union all select '水瓶座',1,20
union all select '双鱼座',2,19
union all select '牡羊座',3,21
union all select '金牛座',4,20
union all select '双子座',5,21
union all select '巨蟹座',6,22
union all select '狮子座',7,23
union all select '处女座',8,23
union all select '天秤座',9,23
union all select '天蝎座',10,24
union all select '射手座',11,22
union all select '魔羯座',12,22
) stars
where dateadd(month,[month] - 1,dateadd(year,year(@) - year(0),0)) + [day] - 1 =
(
select max(dateadd(month,[month] - 1,dateadd(year,year(@) - year(0),0)) + [day] - 1)
from (
select '魔羯座' as star,1 as [month],1 as [day]
union all select '水瓶座',1,20
union all select '双鱼座',2,19
union all select '牡羊座',3,21
union all select '金牛座',4,20
union all select '双子座',5,21
union all select '巨蟹座',6,22
union all select '狮子座',7,23
union all select '处女座',8,23
union all select '天秤座',9,23
union all select '天蝎座',10,24
union all select '射手座',11,22
union all select '魔羯座',12,22
) stars
where @ >= dateadd(month,[month] - 1,dateadd(year,year(@) - year(0),0)) + [day] - 1
)
)
end
--测试示例
select dbo.udf_GetStar('2010-05-04')
select dbo.udf_GetStar('2009-01-04')
select dbo.udf_GetStar('2007-12-04')
--运行结果
/*
金牛座
魔羯座
射手座
*/
- 根据日期返回星座
- [MSSQL]根据日期返回星座
- 【叶子函数分享二十二】根据日期返回星座
- 【叶子函数分享二十二】根据日期返回星座
- 根据日期得到星座
- js根据日期判断星座
- iOS 根据日期判断星座源代码
- 如何根据日期字符串算出星座?
- .net根据日期获取星座方法
- iOS 根据日期判断星座源代码
- 根据日期计算星座的算法
- oj-D-根据日期求星座
- 根据日期获取生肖,根据日期获取星座
- 根据日期字符串或者日期求出星座及属相。
- ASP.NET根据日期获取星座的方法
- 【Java】实现一个根据日期判断星座程序的编写
- 根据日期,转换成星座、生肖工具类
- php根据日期判断星座的函数分享
- spring-mvc3 源码分析
- 过滤掉字符串中重复的字符
- JavaScript学习 5.2.6 操作方法
- 返回指向临时变量的指针
- 扫盲回帖系列之3——在windows下编译生成的程序为什么不能在ubuntu下运行呢?
- 根据日期返回星座
- HTTP 1.1状态代码及其含义
- php对二维数组进行排序、二维数组去掉重复值
- C#内存泄露与资源释放 经验总结
- 计算两个日期之间的工作日
- android学习笔记-AndroidManifest.xml 文件总结
- 根据年月生成日历函数
- SVN 迁移到GIT
- 从第一个汉字开始分割字符串