Home Forums SQL Server 7,2000 T-SQL Help with TSQL, getting StartDate and EndDate from WeekDate !!! RE: Help with TSQL, getting StartDate and EndDate from WeekDate !!!

  • I think this does what you want.select

    DateAdd( dd, 1 - DatePart(dw, WeekDate), WeekDate ) as StartDate,

    DateAdd( dd, 7 - DatePart(dw, WeekDate), WeekDate ) as EndDate,

    OutletId, ProductId, Price, Cost,PromotionType,AdType,DisplayType,[X Value],[Y Value]

    from #PromoHistory;

    The sample data you gave had all entries in a different week. If, however, you have two or more entries within the same week, this would generate duplicate rows in the result set if all the other info in the row was the same. To remove those, use SELECT DISTINCT instead of just SELECT.

    Tomm Carr
    --
    Version Normal Form -- http://groups.google.com/group/vrdbms