• rlindstrom 38273 (11/4/2013)


    There are no Null activity dates. I'm trying to match product codes that have no activity, essentially building that list through the query.

    The RIGHT JOIN to the Product Codes table is generating NULL activity dates. You're even showing them in your expected output (as NULLs).

    LinksUp (11/4/2013)


    To make sure any answer is correct, please read the link under the signature line on how to post questions.

    Can't you just do the following to pick up the null dates:

    where ((coitem_log.activity_date between '7/1/2013 00:00:00:000' and '7/31/2013 23:59:59:999') or coitem_log.activity_date is null)

    LinksUp's suggestion is close but I'd suggest to use the best practice form for filtering on dates, as follows:

    WHERE ((coitem_log.activity_date >= '2013-07-01' AND coitem_log.activity_date < '2013-08-01') or coitem_log.activity_date IS NULL)


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St