I have a table variable that I am joining to actual tables to return some data, which is inserted into a second table variable. The select statement is as follows:INSERT INTO @tmpTable2SELECT r.*FROM @tmpTable1 r INNER JOIN (SELECT ... FROM .....) UNION SELECT ... FROM .....
I then declare two variables that use the data from the second table:DECLARE @level NUMERIC(5,2)DECLARE @allTrue BITSET @level = (SELECT ISNULL(sum((r.colName1/ 100) * r.colName2), 0) FROM @tmpTable2)SET @allTrue = (SELECT CASE WHEN SUM(CASE WHEN r.colName3 = 0 THEN 1 ELSE 0 END) >0 THEN 0 ELSE 1 END FROM @tmpTable2)
I am wondering if there is a way to streamline the code so that I don't have to use the second table variable, but I can't get the syntax correct. Can anyone advise whether it is actually possible to run these 2 queries as a single statement??Thank you.