search a string from all columns from a table

Posted by Sakshi.1947 under Sql Server on 10/15/2012 | Points: 10 | Views : 1369 | Status : [Member] | Replies : 1
hii

i want to search a string from all fields of a table

for that i try OR keyword

select * from table name where bus_name like '%" + abc + "%' OR bus_type like '%" + abc+ "%' OR contact_person like '%" + abc + "%'

but it is a lengthy process .i want to do it in a shorter way.
give me the right direction.




Responses

Posted by: Self-Innovator on: 10/15/2012 [Member] Bronze | Points: 25

Up
0
Down
Try this..
SELECT Tb.NAME AS TABLE_NAME,SCHEMA_NAME(SCHEMA_ID) AS SCHEMA_NAME,Cl.NAME AS COLUMN_NAME FROM SYS.tables AS Tb

INNER JOIN
SYS.columns as Cl ON Tb.object_id=Cl.object_id WHERE Cl.name LIKE 'string%'


Join Hands Change lives
Thanks & Regards
Straight Edge Society

Sakshi.1947, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response