I know it is posible to serach multiple columns with one value.
I would like to serach 3-4 columns for 4 maybe 5 values
I want to check if any of my choosen columns have a certain value in them.
Example
Column 1 | Column 2 | Column 3 | Column 4
| | |
Hello | | | = True
| | |
| Goodbye | | = True
| | Hello | Goodbye = True
| | |
| Hello | | = True
| | |
| | Goodbye | = True
In the example I would like SQL to pull the data from all of the lines that have Hello or Goodbye even both in some cases.
Is there a way to do what I want?
4条答案
按热度按时间q43xntqr1#
There is one more way...
txu3uszq2#
If it's only 3 or 4 columns, the simplest solution would be something like this:
9rygscc13#
Forgot to follow with my solution: I needed to join 2 tables and search across the columns. They ****ed up and made the id of t1 a varchar, smh, and some of them had nulls so we needed to check for them lest our results were ****ed (this is why the selected answer wouldn't work for me). You don't need the aliases but if you were going deeper it helps keep things straight.
Use "+" operator to add columns to a WHERE, check for nulls, and caste if you need too.
c2e8gylq4#
If you want to use wildcards in your criteria patindex is another option
Sample query
the searchText can contains wild card characters , the above query will return the contains like matching 'Biju Kumar' or any character instead on '_' like 'Biju Uumar' from columns [Name] and [Description].