国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

求日期所屬星座的 T-SQL UDF (用戶自定義函數)

2024-07-21 02:06:20
字體:
來源:轉載
供稿:網友

use northwind
go
create function getstar(@ datetime)
returns varchar(100)
as
begin
--僅一句 sql 搞定
return
(
--declare @ datetime
--set @ = getdate()
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(day,[day]-1,dateadd(month,[month]-1,dateadd(year,datediff(year,0,@),0)))
=
(
select max(dateadd(day,[day]-1,dateadd(month,[month]-1,dateadd(year,datediff(year,0,@),0))))
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(day,[day]-1,dateadd(month,[month]-1,dateadd(year,datediff(year,0,@),0)))
)
)
end

go
--測試
use northwind
select dbo.getstar(birthdate),count(*)
from employees
group by dbo.getstar(birthdate)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永昌县| 南郑县| 华容县| 临汾市| 易门县| 密山市| 大姚县| 望江县| 遵义县| 兴文县| 买车| 奇台县| 沙湾县| 清新县| 昆山市| 云霄县| 遂宁市| 西林县| 临邑县| 万年县| 乌拉特后旗| 萝北县| 新竹市| 望江县| 忻城县| 黄浦区| 九龙城区| 台北县| 宜都市| 博野县| 楚雄市| 平江县| 望谟县| 曲麻莱县| 江阴市| 元氏县| 慈利县| 峨眉山市| 福清市| 盈江县| 阿巴嘎旗|