I'm trying to do select from Table2 for each row in an initial select statement from Table1.
Initial select statement would look something like
Select * from Table1 Where GroupID='someId' AND ObjectID='someID'
Table1 would return something like the following (there will only ever be 0-1 returned rows with a null EndDate value).
Table2 will look as follows
Basically my goal is to loop through the first select statements rows. For each row I want to take the objectid, startdate, and enddate to select all the appropriate rows in Table2. Then after do a UNION(?) on all the data I've selected from Table2. I want to be able to select all the rows in Table2 which's objectid matches the objectid given and the timestamp is in-between the start/end dates (or to current timestamp if enddate is null). Does that make sense? I've been looking online, but have not found a way to achieve a looping select union like this.
I'm not sure if this is possible in a single select statement or if a stored proc is needed/cleaner (either is fine but I'd rather avoid stored proc if I can).

