Search a value in all columns of a table – SQL Server
To search a particular value in all columns of a table either you can write lenghty where clause or ypou can unpivot the table and then search in then unpivoted column for the key with single where clause.
CREATE TABLE SearchTable ( RowNumber int identity(1,1), Col_1 nvarchar(10), Col_2 nvarchar(10), Col_3 nvarchar(10) ) go INSERT INTO SearchTable SELECT 'abc','xyz','bcd' INSERT INTO SearchTable SELECT 'ab2','1yz','a2bc' INSERT INTO SearchTable SELECT 'ab3','abc','a2bc' go select * from (select * from SearchTable unpivot ( SearchText for SearchColumn in ([col_1],[col_2],[col_3])) up) pp where pp.SearchText = 'abc' go drop table SearchTable
Popularity: 12% [?]



























What I would not give to have a debate with you about this. You just blurt so many things that come from out of nowhere that Im pretty sure I would have a good shot. Your blog is great to look at, I mean people wont be uninterested. But others who can see past the videos and the layout won’t be so impressed with your generic appreciation of this topic.
I would appreciate more visual materials, to make your blog more attractive, but your writing style really compensates it. But there is always place for improvement
Yahoo! led me to this blog post, and it is everything that I was looking for.