• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 某些條件下求某日的日期

    發表于:2007-05-25來源:作者:點擊數: 標簽:某些條件下某日要得日期
    /*需要得結果: 某一天的日期 已知條件: 這天的年,月,星期幾,在這個月中處于第幾周 舉例說明: 希望求出2004-11-22 已知條件: 2004年, 11 月, 星期一 ,這天在11月是第四周 declare @year numeric(4),@month numeric(2),@weekday varchar(6),@week

    /*需要得結果: 某一天的日期
    已知條件: 這天的年,月,星期幾,在這個月中處于第幾周

    舉例說明:  希望求出2004-11-22
    已知條件: 2004年,  11 月,  星期一 ,這天在11月是第四周

    declare @year numeric(4),@month numeric(2),@weekday varchar(6),@week numeric(1)
    set @year=2004
    set @month=11
    set @weekday='星期一'
    set @week=4
    */

    alter function RequestDate
     (@year numeric(4),@month numeric(2),@weekday varchar(6),@week numeric(1))
    returns datetime as 
    begin

    declare @date1 varchar(10) --得到該月的第一天的日期
    declare @month1 varchar(2)

    if @month<10
     set @month1='0'+ltrim(rtrim(str(@month)))
    else
     set @month1=ltrim(rtrim(str(@month)))

    set @date1=ltrim(rtrim(str(@year))) + '-' + @month1+ '-' + '01'

    declare @num1 numeric(3)
    declare @num2 numeric(3)
    declare @num3 numeric(3)
    set @num1=datepart(ww,@date1)  --得到該月的第一天在該年的周數
    set @num1=@num1+@week-2 --得到該月的要求得的那天所在的周數與該年的第一周第一天的周數差

    set @num2=datepart(dw,dateadd(ww,@num1,'2004-01-01')) --得到日期對應的星期代號

    select @num3=case @weekday
     when '星期日' then 1
     when '星期一' then 2
     when '星期二' then 3
     when '星期三' then 4
     when '星期四' then 5
     when '星期五' then 6
     when '星期六' then 7
    end

    return dateadd(dd,@num3-datepart(dw,dateadd(ww,@num1,'2004-01-01')),dateadd(ww,@num1,'2004-01-01'))

    end

    --  select dbo.RequestDate(2004,11,'星期一',4)



    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>