SQL Server Performance

Adding DATEADD and DATEDIFF to a variable

Discussion in 'General Developer Questions' started by rahils573, Sep 3, 2004.

  1. rahils573 New Member

    Hello Everybody ,
    I want to introduce a variable where I can add DATEADD(hh, DATEDIFF (HH , @StartDate, @EndDate ), @DateDiff ) to a variable in my CASE Statement .So finally I have a single variable where all the DATEADD are add to it.How do I do that .Please guide.

    Rahil

    Set @StartDate='08:00 AM'
    Set @EndDate='05:00 PM'
    Set @DateDiff= 0
    Set @DateDiff1= DATEADD(hh, DATEDIFF (HH , @StartDate, @EndDate ), @DateDiff )
    Set @DateDiff2= DATEDIFF (HH,@StartDate,@EndDate) + @DateDiff1

    SELECT
    CASE
    WHEN @MyaspDate>@EndDate THEN DATEADD(hh, DATEDIFF (HH , @StartDate, @EndDate ), @DateDiff )
    WHEN @MyaspDate>@StartDate and @MyaspDate<@EndDate THEN DATEDIFF (HH,@StartDate,@EndDate) + @DateDiff1
    WHEN @MyaspDate<@StartDate THEN DATEDIFF(HH, @StartDate,@EndDate) + @DateDiff2
    ELSE 0
    END AS "Time Category"
    FROM ScheduleItems
    ORDER BY ScheduleItemID
  2. Luis Martin Moderator

    Kindly don't duplicate post. I've deleted other one.


    Luis Martin
    Moderator
    SQL-Server-Performance.com

    All postings are provided “AS IS” with no warranties for accuracy.

  3. FrankKalis Moderator

  4. FrankKalis Moderator

Share This Page