打印本文 打印本文 关闭窗口 关闭窗口
SQL 以日期动态更新维护的数据,一周排程时间日期设计
作者:武汉SEO闵涛  文章来源:敏韬网  点击数27578  更新时间:2007/11/14 12:58:28  文章录入:mintao  责任编辑:mintao
nbsp;                  

 DEALLOCATE  Cu_PartDate          

 

     ---------------查询用户设置的时间范围 ------------------------------

select t1.*  into #tmpTodate From  #ToDate t1 ,

(Select distinct PartnumRevision = Partnum+Revision

  From #ToDate

   Where Qnty>0 and ((TodayTime>=@BDate or @BDate='''''''')

               and (TodayTime <=@EDate or @EDate =''''''''))) t2

Where  (t1.Partnum+t1.Revision)  = t2.PartnumRevision

 

        ------------------------------转换数据显示格式-----------------------------

Select top 0  Dateid, Partnum, Revision, Qnty1,Qnty2,Qnty3,Qnty4,Qnty5,Qnty6,Qnty7, Todate

Into #WeekProcedure

From Pdl_WeekProcedure

 

declare @str varchar(8000)

set @str =''''''''

select @str =@str+'''',[''''+rtrim(DateStr)+'''']=max(case TodayTime when ''''''''''''+rtrim(TodayTime)+'''''''''''' then Qnty else '''''''''''''''' end)''''

from #tmpTodate group by TodayTime,DateStr Order by DateStr

 

Select @str = Isnull(@str,''''0,0,0,0,0,0,0'''')

 

 

If (Exists( select * from #tmpTodate)) and (@Flage = 0)

 Begin

  Insert Into #WeekProcedure(Dateid, Partnum, Revision, Qnty1,Qnty2,Qnty3,Qnty4,Qnty5,Qnty6,Qnty7, Todate)

  exec(''''Select Dateid, Partnum, Revision ''''+@str+'''' ,Todate From #tmpTodate Group By Dateid, Partnum, Revision, Todate'''')

 

  Update t1 Set  t1.[A0]=t2.Qnty1, t1.[A1]=t2.Qnty2, t1.[A2]=t2.Qnty3, t1.DelDate =t2.Todate,

                        t1.[A3]=t2.Qnty4, t1.[A4]=t2.Qnty5, t1.[A5]=t2.Qnty6, t1.[A6]=t2.Qnty7

   From #StknWipTotal t1, #WeekProcedure t2(nolock) 

  Where Ltrim(Rtrim(t1.PartNum)) = Ltrim(Rtrim(t2.PartNum))

 << 上一页  [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]  ...  下一页 >> 

打印本文 打印本文 关闭窗口 关闭窗口