• 将数据平均分配到一个时间段内,周末去掉(精典)


    最近写了一段SQL,因为时间跳变的原因,需要将一些数据平均分配到一个日期段内,但是周末要除外,在此PO出来,希望有需要的朋友可以瞄两眼,呵~~~~

    declare @datetime datetime
    declare @datetimey datetime
    declare @termrecordid int
    set @datetime='2009-07-09'   --此处设定的是一个初使的值,后面会根据情况进行累加
    declare update_cursor cursor for

    select termrecordid,consumedate from te_consumedetailxf where termid=229 and
    convert(char(10),consumedate,21) between '2005-01-01' and '2005-12-01'
    and consumedetailid between '134900' and '170987' order by termrecordid

    open update_cursor
    fetch next from update_cursor
    into @termrecordid,@datetimey

    while @@FETCH_STATUS = 0
    begin

    if (@termrecordid%14 = 0)    --一天插入14条,满14条时,日期要向前加一
    begin
    set @datetime=dateadd(day,1,@datetime)   
    SET DATEFIRST 1
    select DATEPART(WEEKDAY,@datetime)   
    select @datetime=
           case DATEPART(WEEKDAY,'2009-02-01') when 6 then dateadd(day,2,@datetime)
           when 7 then dateadd(day,1,@datetime)  else @datetime end                     
    end     --此处是判断是否为周末,若为周6则再加一,若为周日则再加二
     

    update te_consumedetailxf
    set consumedate=convert(datetime,@datetime+''+convert(varchar(10),@datetimey,114))
    where termid=229 and
    (convert(char(10),consumedate,21) between '2005-01-01' and '2005-12-01' )
    and (consumedetailid between '134900' and '170987') and termrecordid=@termrecordid

    fetch next from update_cursor into
    @termrecordid,@datetimey

    end

    fetch next from update_cursor

    close update_cursor
    deallocate update_cursor
    希望可以帮到有需要的朋友,如果没有需要也可以留着备用哦,嘻嘻~

  • 相关阅读:
    031:verbatim 标签
    030:spaceless和autoescape 标签
    WinForm webbrowser控件的使用
    c# WebBrowser开发参考资料--杂七杂八
    C# Winform WebBrowser控件
    使用webBrowser进行C#和JS通讯
    webBrowser 应用编程函数总结
    C#网页采集数据的几种方式(WebClient、WebBrowser和HttpWebRequest/HttpWebResponse)
    利用WebBrowser控件实现百度自动搜索
    c#winform使用WebBrowser 大全
  • 原文地址:https://www.cnblogs.com/medci/p/1574501.html
Copyright © 2020-2023  润新知