Hey Bebe!

Assuming #WorkingData field structure is something like:

Field Name .......... Datatype
ledger_id .............. integer (or long, double, single, numeric, whatever)
invoice_date1 ....... datetime
invoice_date2 ....... datetime

You won't have many records where the ledger_id is both NULL and less than zero, so you should change that part of your SARG.

Then, assuming invoice_date1 is earlier than invoice_date2 (since you otherwise get a negative return), the next hurdle is to avoid calculating a DATEDIFF return for null dates or a range greater than an integer value.

See if something like this work.

Code:
SELECT COUNT (*)			
	FROM #WorkingData	
	WHERE ledger_id < 0
	AND DATEDIFF ( hh
          , ISNULL( invoice_date1, GETDATE() )
          , ISNULL( invoice_date2
              , ISNULL( invoice_date1, GETDATE() ))) > 1
Hope this helps.