title: SQL Server query to select all columns of a certain type and also show its max values
body: <p>I am using SQL Server 2012.</p>
  
  <p>The first part of my query is already answered in this <a href="https://stackoverflow.com/questions/9678260/find-all-columns-of-a-certain-type-in-all-tables-in-a-sql-server-database">thread</a>. But I also want a second column that will show the corresponding maximum value of that column in its corresponding table. </p>
  
  <p>I have tried this approach: use a function that takes in table name and column name as parameter and return the max value. But it is illegal to use dynamic SQL from a function. Moreover, i cannot seem to call a function from within a SELECT query. </p>
  
  <p>I have also tried using stored procedure, but i cannot figure out how to call it and use it. Please suggest alternative ways to achieve this.</p>
  
  <p>I am new to SQL Server.</p>
  
  <p>Thanks</p>