Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 want to search in 2 or more than columns....

Author  Topic 

asifbhura
Posting Yak Master

165 Posts

Posted - 2009-12-22 : 04:32:31
Hi,

I want to search text in 2 or more than 2 columns at time

i did like below it works, i want solutions better than that,

normally we search only in one columns as like
SELECT * FROM News WHERE news_detail like '%USA%'

but for 2 more than two i tried like below
please give me better solution

SELECT * FROM News WHERE news_detail like '%USA%'
UNION
SELECT * FROM NEWS where news_title like '%USA%'

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-12-22 : 04:37:38
HI

If you using SQL SERVER 2008 You can use the CONTAINS predicate to query multiple columns by specifying a list of columns to search.

Note
The columns must be from the same table.




-------------------------
R...
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2009-12-22 : 08:20:20
Why use a union?
U can use something like this

SELECT * FROM News WHERE (news_detail like '%USA%')OR(news_title like '%USA%')


PBUH
Go to Top of Page
   

- Advertisement -