The multi-part identifier > "a.surveyid" could not be bound I am getting the error :


  Msg 4104, Level 16, State 1, Line 1 The multi-part identifier
  "a.surveyid" could not be bound.


Below is the query ,what could be the issue?

 SELECT a.surveyid,* 
    FROM [360HRSurvey] where sempid IN ( 
     SELECT  a.EmpCode  
     FROM surveyusers a  
     where a.surveyid = 80 and a.EmpCode NOT IN (
      SELECT p.EmpID    
      FROM empsurveyselection p 
      WHERE p.surveyid =80)
    and empid =   ( 
      SELECT empid 
      from [360HRSurveyEmployee] 
      where surveyid = 80)
    )
You need to use surveyid not a.surveyid. Because surveyusers as a declare in sub-query so you can not access a.surveyid in main query.