title: Conversion failed when converting the varchar value 'SELECT ' to data type tinyint
body: <p>I am trying to get value of a column of a particular row but I am getting following error. I don't know what's the problem. Here is my sql query:</p>
  
  <pre><code>declare @Service_Table varchar(30),
          @Ser_Id tinyint,
          @sql  nvarchar(100), 
          @Service_State tinyint
  
  SET @Service_Table='Third_Party_Assistance'
  set @Ser_Id = 2
  SET @sql = 'SELECT ' + @Service_State + '=  Service_State_Id FROM dbo.' + 
            quotename(@Service_Table) + ' WHERE Service_Id = ' + 
            convert(varchar,@Ser_Id) + 'AND Service_State_Id &lt;&gt; 4'
  EXEC sp_executesql @sql
  </code></pre>