title: How to set flag in a select statement in a SQL statement
body: <p>I got Employee table where I select employee records when employee id is supplied, with in which I have to enable a flag if the employee record exists with 1 otherwise 0. I'm trying to accomplish this using the following script:</p>
  
  <pre><code>DECLARE @FLAG INT
  DECLARE @EMPID VARCHAR(10)
  
  SELECT  CASE WHEN COUNT(*) &gt; 0 THEN 1 ELSE 0 END AS @FLAG, 
          E.EMPID,
          E.EMPNAME, 
          E.DESIGNATION 
  FROM 
      EMPLOYEE E LEFT JOIN  
      GEO23.EMPLOYEEDETAILS ED ON E.EMPID = ED.EMPID 
  WHERE E.EMPID = @EMPID
  ORDER BY E.EMPID DESC
  </code></pre>
  
  <p>But this results in error. Can somebody please help. Please note I'm an amateur in SQL</p>