title: Dynamic query is not giving desired result
body: <p>I am creating dynamic query which is updating column if it exists in the table. When update query is running it giving error. Following is the procedure </p>
  
  <pre><code>Create Procedure spr_UpdateColumnWithTotalPrice
  @id int
  as
  begin
  
  if not exists
  (
      Select * from INFORMATION_SCHEMA.COLUMNS
      where TABLE_NAME = 'Product'
      and
      COLUMN_NAME = 'ProductSellingPrice'
  )
  Begin
      Declare @SellingPrice varchar(max)
  
  
      Set @SellingPrice = 'Alter table Product add ProductSellingPrice int'
      Exec(@SellingPrice)
  
      Print 'Table altered'
  End
  Else
  Begin
          Set @SellingPrice = 'Update Product set ProductSellingPrice = ((UnitPrice * [GSTRATE%]/100) + UnitPrice ) where  ProductID  = @id'
          Exec(@SellingPrice)
          Print 'Table updated'
  End
  </code></pre>
  
  <p>end</p>
  
  <p>I am getting following result :-</p>
  
  <blockquote>
    <p>Conversion failed when converting the varchar value 'Update Product set ProductSellingPrice = ((UnitPrice * [GSTRATE%]/100) + UnitPrice ) where  ProductID  = @id' to data type int.</p>
  </blockquote>
  
  <p>Please help and thanks in advance</p>