zoukankan      html  css  js  c++  java
  • 根据日期返回星座

    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')

     

    --运行结果

    /*

    金牛座

    魔羯座

    射手座

    */

  • 相关阅读:
    zabbix监控
    ipv4固定ip地址
    CentOS7 内核优化 修改参数
    流媒体服务器 red5
    linux安装git
    zabbix-钉钉报警媒介
    Windows下利用IIS建立网站并实现局域网共享
    docker的简单操作和端口映射
    docker概述和安装及基本操作
    VMware Workstation创建Windows2012server虚拟机
  • 原文地址:https://www.cnblogs.com/accumulater/p/6244587.html
Copyright © 2011-2022 走看看