I want to be able to check if a specific record (in this case "under" has been created after an initial record has been created and show that in a separate with either "under" or null.
Example Data
Received Name Sub
01-Jun Mike Over
01-Jun John Over
02-Jun Dave Between
03-Jun Pete Over
02-Jun Mike Under
03-Jun Dave Under
Desired Results
Received Name Sub Sub2
01-Jun Mike Over Under
01-Jun John Over Null
02-Jun Dave Between Under
03-Jun Pete Over Null
I am working from this code but its so horribly wrong that I cant see the wood for the trees anymore.
DECLARE @TM DATETIME;
SET @TM = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', GETDATE()), '19000101');
select
t1.received,
t1.name,
t1.sub,
t2.sub as sub2
from
dbo.tblOpen t1
join dbo.tblOpen t2 on t1.name = t2.name
where
t1.closed >= DATEADD(MONTH, -1, @TM)
Can I get a point in the right direction here please.