title: Conversion failed when converting the varchar value to datatype int
body: <p>Below is the query I have written</p>
  
  <pre><code>DECLARE @entityName VARCHAR(20) = 'Job'
  DECLARE @sql VARCHAR(MAX); 
  DECLARE @userId INT = 4
  
  SET @sql = 'select v.Id,[Title], [HiringCompany], [EmploymentType], 
                     [Status], [Priority], [ExperienceLevel], [Salary], 
                     [Location], [AssignedRecruiter], 
                     [PipelineCount], [CreationDate],
                     [Department], [PublishingStatus], 
                     CASE WHEN f.Id &gt; 0 THEN 1 ELSE 0 END as IsFavourite 
               from JobListView v 
               left join (select * from Favourite 
                          where EntityType = '''+ @entityName +''' 
                            and IsDeleted = 0 and userId = '+ @userId +') f on v.Id = f.EntityId';
  
  EXEC (@sql)  
  </code></pre>
  
  <p>This is the exception I am getting:</p>
  
  <blockquote>
    <p>Conversion failed when converting the varchar value 'select v.Id,[Title], 
        [HiringCompany], [EmploymentType], [Status], [Priority], 
        [ExperienceLevel], [Salary], [Location], [AssignedRecruiter], 
        [PipelineCount], [CreationDate],
        [Department], [PublishingStatus], CASE WHEN f.Id > 0 THEN 1 ELSE 0 END as 
        IsFavourite from<br>
        JobListView v Left join (select * from Favourite where EntityType = 'Job' 
        and IsDeleted = 0 and userId = ' to data type int.</p>
  </blockquote>
  
  <p>May I know what I have missed in my query?</p>