how to calc % using datediff() sqlserver 2005

  • I feel stupid + lame asking this - I've been using SQL server for 10 years:

    In this problem there are 3 dates pertaining to a project:

    Start date, Current date, End date. I need to know what

    is the “percent done” (in days) of the project.

     

    Example, if start date = 3/1/07, current date = 3/10/07,

    and end date = 3/31/07, Then “percent done” would be

    about 33.3%. I need to add the ‘%’ at the end too.

     

    I tried this but sqlserver 2005 would not accept it:

      datediff(day, start_date, getdate()) / datediff(day, start_date, end_date)

     

    Please help the lame one...........

     

  • >>sqlserver 2005 would not accept it

    Did you get a syntax error ? Or the wrong result ?

    Declare @Startdate Smalldatetime

    Declare @EndDate Smalldatetime

    Declare @Currentdate Smalldatetime

    Select @StartDate = '01 Mar 2007', @EndDate = '31 Mar 2007', @CurrentDate = '10 Mar 2007'

    Select 100.0 * (datediff(dd, @startdate, @CurrentDate) + 1.0 ) / datediff(dd, @startdate, @enddate)

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply