title: Finding column in a table and pull the the values if exist else refer other column
body: <p>Im trying to check for a column[EMPID] in a table [EMPLOYEE] if exist i have to consider the values from that column, if not it have to refer to another TAble[Details] and column[EMPID]. Please somebody can answer this. </p>
  
  <pre><code>select distinct EMPLYEENAME,(
  select case 
     when exists (select 1 from sys.columns where Name = 'EMPID' and 
     object_id=object_id('EMPLOYEE'))
     then 1
     else 0 
  end EMPID) EMPID from EMPLOYEE
  )k
  </code></pre>
  
  <p>so here in the place of '1' and '0' i have to pull values from DETAILS table and EMPLOYEE table</p>