TSQL Passing a varchar variable of column name to SUM function <p>I need to write a procedure where I have to sum an unknown column name.</p> <p>The only information I have access to is the column position.</p> <p>I am able to get the column name using the following:</p> <pre><code> SELECT @colName = (SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='TABLENAME' AND ORDINAL_POSITION=@colNum) </code></pre> <p>I then have the following: </p> <pre><code> SELECT @sum = (SELECT SUM(@colName) FROM TABLENAME) </code></pre> <p>I then receive the following error: </p> <blockquote> <p><em>Operand data type varchar is invalid for sum operator</em></p> </blockquote> <p>I am confused about how to make this work. I have seen many posts on convert and cast, but I cannot cast to an float, numeric, etc because this is a name.</p> <p>I would appreciate any help.</p> <p>Thank you</p>