为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

SQL 根据日期返回星座

2017-09-19 2页 doc 30KB 34阅读

用户头像

is_882336

暂无简介

举报
SQL 根据日期返回星座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 selec...
SQL 根据日期返回星座
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')   --运行结果 /* 金牛座 魔羯座 射手座 */
/
本文档为【SQL 根据日期返回星座】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
热门搜索

历史搜索

    清空历史搜索