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
 General SQL Server Forums
 New to SQL Server Programming
 Output search criteria for multiple OR

Author  Topic 

Gary_H
Starting Member

2 Posts

Posted - 2014-10-21 : 06:09:55
My selection criteria is as follows:

where content like '%EditLiveJava%'
or content like '% Sys__%' ESCAPE '_'
or content like '%<div class="row"/>%'
or content like '%<a href="" title=""%'
or content like '%cmsprod%'
or content like '%Error processing inline link%'
or content like '%see log for stack trace%'

I output the content field if the search is true but would like to also output which specific 'like' has been found.
Can I do this in the one pass or do I have to read the database separately for each condition?

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-21 : 08:43:35
Once you get a hit, you'll need to try each condition separately to figure out which one it was. BTW The way you've written the LIKE clauses, these are not SARGs and will not use any index set up on the column 'content'. Have you considered full-text search? Is that an option in your setup?
Go to Top of Page

Gary_H
Starting Member

2 Posts

Posted - 2014-10-21 : 09:20:39
This code does work. I'm searching for assembly errors in full page code (content). I was just wondering if there was an easier way to indicate which of the searches was found. At the moment, if I get a hit I then manually search the content column afterwards to find which one it was.
I'm just starting out in SQL. I'm from an RPG400 background and my logic says that I should be able to allocate an indicator to each value that will automatically switch on if the argument is true which I can then output with the column details. I know I'm not comparing eggs with eggs but thought it was worth asking.
Thanks for looking and responding.
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-21 : 09:25:42
Keep in mind that SQL is set-based. Conceptually, all conditions are tested at once. The way you've coded it, ALL conditions could be true for some content. Also, the SQL compiler will not necessarily process the tests in the order you write them.

Really, this is a text-book case for full-text search. Talk to your DBA about getting that set up. You still won't get any indicator of which condition was matched, but the search should be much faster.
Go to Top of Page
   

- Advertisement -