Date Between Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • baburk
    New Member
    • Oct 2006
    • 111

    Date Between Problem

    Hi all,

    I want to get result for a praricular ID if all days are present.

    But I am getting result if any of the day present in between the date


    select StarRate, Date from vw_BasicSearch where date BETWEEN CAST('2008-06-03' AS DATETIME)
    AND CAST('2008-06-05' AS DATETIME)
    AND StarRate = 5
    group by StarRate, Date


    Result.

    StarRate Date
    --------------------------

    5 2008-06-04 00:00:00.000
    5 2008-06-05 00:00:00.000

    Thanks
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    But I am getting result if any of the day present in between the date
    That is what the BETWEEN() function does.
    I want to get result for a praricular ID if all days are present
    Are you looking for a date entry of evey day covering a period. Two months in your example?

    Comment

    • deepuv04
      Recognized Expert New Member
      • Nov 2007
      • 227

      #3
      hi,
      try the following query

      [code=sql]
      SELECT vw.StarRate, vw.Date
      FROM vw_BasicSearch as vw INNER JOIN
      (SELECT StarRate,Count( Distinct Date) AS DAYS
      FROM vw_BasicSearch
      group by code )AS T on T.StarRate = Prod.StarRate
      AND DAYS = datediff(dd,GET DATE() - 3,GETDATE()) + 1
      [/code]

      thanks

      Comment

      • Delerna
        Recognized Expert Top Contributor
        • Jan 2008
        • 1134

        #4
        nice idea there deepuv

        Comment

        Working...