Let’s say I have a query like this:
Select col1,
col2,
(select count(smthng) from table2) as 'records'
from table1
I want to filter it to be not null for ‘records’ column.
I cannot do this:
Select col1,
col2,
(select count(smthng) from table2) as 'records'
from table1
where records is not null
The best I came up with is to write this resultset to a Table Value parameter and have a separate query on that resultset. Any ideas?
Just move it to a derived query. You cannot use a column defined in the SELECT clause in the WHERE clause.