DataGrid如何邦定一個星期的數據
存儲過程該如何寫。
ID   DataTime       Subject     
1    2006-04-02     公司會議
2    2006-04-12     公司會議
3    2006-04-22     公司會議
4    2006-05-12     公司會議
按照表裏Datetime邦定DataGrid,判斷時間是在同一個星期的就邦定到DataGrid.

解决方案 »

  1.   

    你的存储过程显然需要传一下日期参数以确定该星期所处的日期,不知道你用什么数据库,如果是Oracle,可以这样获取:select * from mytable where trunc(日期字段名,'IW')=trunc(v_Date,'IW');其中的“日期字段名”是你的数据库中日期字段的名称,v_Date是存储过程传入的日期参数。SQL Server中用DatePart函数应该可以实现相同的效果,只是这段时间一直用Oracle开发,没有装SQL Server,无法测试,你只好自己试一试了
      

  2.   

    sample code as followsCreate procedure GetWeekData @StartDate DateTime AS
    Declare @EndDate DateTime
    Set @EndDate = DATEADD ( day , 7, @StartDate ) 
    Select ID,yourDataTime,Subject From yourTable Where yourDataTime>= @StartDate 
    And yourDataTime < @EndDate
    传进参数的时候,只需给出起始日期即可