I am using Sql Server 2014
I have an expensive query. I want to insert the results of that query into a table.
However the results should match a certain condition, if they don't I don't want to insert them, but I do want to return them so that my application can warn/record these violations.
So essentially I want to run both of the following:
INSERT INTO MyTable
SELECT ExpensiveQuery
WHERE MyCondition;
SELECT ExpensiveQuery
WHERE Not MyCondition;
But I don't want to run the expensive query twice.
Is this possible?