SQL Server SELECT where any column contains 'x'

select, sql, sql-server, sql-server-2008

Solution

You can use `in`:

SELECT *
FROM testing 
WHERE 'foo' in (col1, col2, col3, . . . );

Problem

Using SQL Server 2008, say I have a table called `testing` with 80 columns and I want to find a value called `foo`. I can do: ``` SELECT * FROM testing WHERE COLNAME = 'foo' ``` Is it possible I can query all 80 columns and return all the results where `foo` is contained in any of the 80 columns?

Original source

Related problems