I am trying to achieve something of this sort in SSIS OLEDB Source.
1) Count the records in the exception table
2) If there are exceptions, write the data to excel sheet
3) If not, write ‘No data available’
I wrote a simple query for doing this, but get the error
Msg 116, Level 16, State 1, Line 3
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
SELECT CASE WHEN (SELECT COUNT(*) FROM exceptionTable) > 0 THEN
(SELECT * FROM exceptionTable) ELSE 'No Error data available' end
I understand what the error message says and know how to solve it, but I cant think of an alternative solution to this problem. Any help will be appreciated. Thanks.
You should be able to handle this using the EXISTS keyword. Something along these lines should do the trick:
The EXISTS keyword specifies a subquery that can be used to test for the existence of any rows that are returned by the subquery. If no rows are returned, it evaluates to false and the ELSE clause is executed.