SQL Server nested select in from clause -
sorry, not being clear. current query looks below , working fine except conditions.
select a.*, (select .... emp name = a.name...... ) (select .... emp name = a.name...... ) ........ (select distinct column1, column2, column3 xxx condition1)
sometimes, below query i.e in clause gives no results.
select distinct column1, column2, column3 xxx condition1
when no results above sub query, don't want below queries fail due join
(select .... emp name = a.name...... ) (select .... emp name = a.name...... )
when subquery from cause returns no results display in emp table without join i.e without name = a.name
when subquery from cause returns results display in emp table join i.e name = a.name
hence, trying add case statement below check if subquery gives results. maybe there better way achieve this.
please need on this.
select a.*, case when exists (select a.*) (select .... emp condition 1...... ) when not exists (select a.*) (select .... emp condition 2...... ) end column_dummy (select distinct column1, column2, column3 xxx condition1)
as suggested when try giving below getting error invalid object name 'a'
select a.* case when (select count(*) ....) = 0 'not result' else 'you have there ' end
use query count(*)
select a.* case when (select count(*) table ....) = 0 `not result` else `you have there` end
Comments
Post a Comment