Do I need to create a temp table?

  • I want to find out the number of Fridays between a certain date range. Do I need to create a table that I could select from first?

  • NO you don't but it may be easier to maintain

    In any case if you don't want to create the table just use:

    declare

      @start datetime

    , @end   datetime

    select

      @start = '20040306'

    , @end   = '20040326'

    select  datediff (wk, @start, @end)-1

     + case  when datepart (dw, @end)   >= 6 then 1 else 0 end

     + case  when datepart (dw, @start) <= 6 then 1 else 0 end  as NoFridays


    * Noel

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

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