I have an SQL query that returns two columns (always one row):
SELECT SUM(firstmeasure) as col1, COUNT(*) as col2
FROM
(SELECT date1, date2, CASE WHEN DATEDIFF(date1,date2) < 20 THEN 1 ELSE ) End 'firstmeasure'
FROM table1)x
WHERE date1 >= '01/01/2024'
col1 | col2 |
---|---|
100 | 180 |
I would like to INSERT both of these values into another table (essentially it is recording the point-in-time result of the query)
INSERT INTO table2(col1, col2)
How do I do this without executing the query twice? For example I am able to assign the result of the query to 1 variable and insert that, but only if the query is reduced to only producing 1 column.