Suppose I have
INSERT INTO @tmp1 (ID) SELECT ID FROM Table1 WHERE Name = 'A'
INSERT INTO @tmp2 (ID) SELECT ID FROM Table2 WHERE Name = 'B'
SELECT ID FROM @tmp1 UNION ALL SELECT ID FROM @tmp3
I would like to run queries 1 & 2 in parallel, and then combine results after they are finished.
Is there a way to do this in pure T-SQL, or a way to check if it will do this automatically?
A background for those who wants it: I investigate a complex search where there're multiple conditions which are later combined (term OR (term2 AND term3) OR term4 AND item5=term5) and thus I investigate if it would be useful to execute those - largely unrelated - conditions in parallel, later combining resulting tables (and calculating ranks, weights, and so on).
E.g. should be several resultsets:
SELECT COUNT(*) @tmp1 union @tmp3
SELECT ID from (@tmp1 union @tmp2) WHERE ...
SELECT * from TABLE3 where ID IN (SELECT ID FROM @tmp1 union @tmp2)
SELECT * from TABLE4 where ID IN (SELECT ID FROM @tmp1 union @tmp2)