Imagine a table like this:
create table #productPurchases
( intRowId int identity(1,1),
It holds a record of items purchased and the date they were purchased. How would I write a query to identify items that had been purchased both before *and* after a certain date?
Tried this. Which didn't work, and bought back rather more records than I was expecting, mostly duplicates (the real table is a lot bigger) - but it illustrates what I'm trying to do.
SELECT TOP 1000 *
FROM #productPurchases e1
join #productPurchases e2
on e1.strItemId = e2.strItemId
where e1.datPurchaseDate> '2013-05-09 00:00:01'
and e2.datPurchaseDate < '2013-05-09 00:00:01'