• drew.allen (7/6/2015)


    You were actually very close. The problem is here.

    order by ABS (DateAdd(Minute, 30 * (DateDiff(Minute, 0, closedate) / 30), 0)) ASC

    DATEADD() returns a date/time and ABS() takes a float, and it can't implicitly convert a datetime to a float.

    The other thing I would suggest is that instead of this:

    and day (close_date) = '03'

    and month(close_date) = '08'

    and year (close_date) = '2014'

    you try this:

    and CAST(close_date AS DATE) = '2014-08-03'

    Drew

    You really should avoid all functions on columns whenever possible. Thus, here's the preferred method:

    (close_date >= '20140803' and close_date < '20140804')

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.