October 5, 2018 at 5:53 am
Hello all,
I am stuck with how to approach this task.
I have an error table that has error text held as a string.
I have a lookup table with generic substrings in it and their corresponding categories.
Example here:
What I want to do is test the error string for all of these substrings and then return the category if it finds a match.
Does anyone have any experience doing this? I can't quite decide where to begin.
Sorry to be so vague.
Dave
October 5, 2018 at 5:56 am
One method is to use CHARINDEX. Performance on a large dataset will (probably) not be very good, however. Doing lots of pattern matching on a string in SQL Server is not it's forté. Have a look at the documentation and have a try; if you don't succeed post your attempt and we'll see where you went wrong.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
October 5, 2018 at 6:33 am
Yes, or you can use LIKE. I don't know whether it'll be more or less efficient than CHARINDEX, or exactly the same - you'll need to test.
SELECT l.Category
FROM ErrorTable e
JOIN Lookup l ON e.ErrorText LIKE '%' + l.SearchString + '%'
John
October 5, 2018 at 6:44 am
John Mitchell-245523 - Friday, October 5, 2018 6:33 AMYes, or you can use LIKE. I don't know whether it'll be more or less efficient than CHARINDEX, or exactly the same - you'll need to test.
SELECT l.Category
FROM ErrorTable e
JOIN Lookup l ON e.ErrorText LIKE '%' + l.SearchString + '%'John
Hi Thanks for the replies. I used Like and it worked just fine. I only had 25 substrings to test though so performance was never going to suffer in this instance.
Regards
Dave
October 6, 2018 at 8:45 pm
Joe Torre - Friday, October 5, 2018 3:05 PM
Ok, Joe. Let's say you took the time to setup FTS. What would the query be to solve the OP's problem?
--Jeff Moden
Change is inevitable... Change for the better is not.
October 6, 2018 at 8:46 pm
david_h_edmonds - Friday, October 5, 2018 5:53 AMHello all,
I am stuck with how to approach this task.
I have an error table that has error text held as a string.I have a lookup table with generic substrings in it and their corresponding categories.
Example here:
What I want to do is test the error string for all of these substrings and then return the category if it finds a match.
Does anyone have any experience doing this? I can't quite decide where to begin.
Sorry to be so vague.
Dave
Have you some real samples of real error strings that we could take a look at?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy