title: How to dynamically calculate sum of multiple unknown columns in sql?
body: <p>I have multiple columns with some amount in a table and I want to show the total of all those amounts in the last Total column. I have a table in sql which looks somewhat like this,</p>
  
  <pre><code>A_Amt  B_Amt  C_Amt  D_Amt  E_Amt  F_Amt ... Total
  ------------------------------------------------
   15     20     25     30     35    40       
  </code></pre>
  
  <p>I do not want to do <code>sum(col1 + col2 + ..)</code> like this because there are many columns. Is there another way to get the sum using a where clause like <code>**where columnname.name like '%Amt%'**</code>?</p>
  
  <p>I am trying to use <code>UNPIVOT</code> and I came up with the following code but it is not working,</p>
  
  <pre><code>select Product_ID, Amount
  FROM Products
  unpivot
  (Amount for Product_ID in 
  (select c.name + '' from syscolumns c(nolock) where (id = 
  (select id from dbo.sysobjects where name = 'Products'))
  and (c.name like '%Amt%')))
  </code></pre>
  
  <p>Any ideas will be helpful.</p>