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.
| Author |
Topic |
|
sbt1
Yak Posting Veteran
89 Posts |
Posted - 2005-09-09 : 14:30:36
|
| I'm implementing a search; I'd like to find a way to write a query find a search string in any field of a table, instead of writing it like this:... WHERE [Field1] LIKE %searchstring%OR [Field2] LIKE %searchstring% OR [Field3] LIKE %searchstring%OR [Field4] LIKE %searchstring%Is there a way to do this?How about in multiple tables? |
|
|
nosepicker
Constraint Violating Yak Guru
366 Posts |
Posted - 2005-09-09 : 22:45:55
|
| I'm not sure if this will be any faster or easier, but it's at least an alternative:SELECT * FROM (SELECT field1 AS col FROM YourTable UNION SELECT field2 AS col FROM YourTable UNIONSELECT field3 AS col FROM YourTable UNIONSELECT field4 AS col FROM YourTable) AS A WHERE A.col LIKE '%searchstring%'You could also make the derived table into a view, temp table or table variable. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
|
|
|
|
|