As always, I suggest xml for this (I would suggest JSON if SQL Server had built-in support :) :). You can try using this query, although it may not work as well with a large number of lines:
;with cte as ( select *, (select t.* for xml raw('data'), type) as data from test as t ) select * from cte where data.exist('data/@*[local-name() != "id" and contains(., sql:variable("@search"))]') = 1
see sql fiddle demo for a more detailed example.
It is important to note Alexander Fedorenko in the comments: it should be understood that the contains function is case sensitive and uses xQuery's default Unicode code point to compare strings.
A more general way is to use a dynamic SQL solution:
declare @search nvarchar(max) declare @stmt nvarchar(max) select @stmt = isnull(@stmt + ' or ', '') + quotename(name) + ' like @search' from sys.columns as c where c.[object_id] = object_id('dbo.test') -- -- also possible -- -- select @stmt = isnull(@stmt + ' or ', '') + quotename(column_name) + ' like @search' -- from INFORMATION_SCHEMA.COLUMNS -- where TABLE_NAME = 'test' select @stmt = 'select * from test where ' + @stmt exec sp_executesql @stmt = @stmt, @params = N'@search nvarchar(max)', @search = @search
sql fiddle demo
source share