title: Search table columns for values over a certain length
body: <p>So I have a database with many tables that have a column that contains a GL Account value (for financial purposes). The column name varies by table (i.e. in one table the column is called "gldebitaccount" and in another table it's called "glcreditaccount"). I was able to find all combinations of table / column pairs using the following query:</p>
  
  <pre><code>SELECT c.name AS ColName, t.name AS TableName
  FROM sys.columns c
      JOIN sys.tables t ON c.object_id = t.object_id
  WHERE c.name LIKE '%gl%acc%'
  </code></pre>
  
  <p>This query returns close to 100 pairs of tables/columns. I am trying to find any value in any of those table/column pairs that exceeds 25 chars in length. For an individual table/column, I'd typically use:</p>
  
  <pre><code>SELECT *
  FROM tableName
  WHERE LEN(columnName)&gt;25
  </code></pre>
  
  <p>I want to avoid having to run that query 100 times with each pair. Is there any way I can do a "for each" (which I know is frowned upon in SQL since everything should be set-based). I've done sub-SELECT statements before, but not any that involved change the table in the FROM clause. Any ideas or help would be greatly appreciated!</p>
  
  <p>Thanks in advance!</p>