I am currently trying to overhaul the current keyword search I have put into the scripting software we use (the old one was vey basic and cumbersome) to something more refined. There are limitations to the software we use, and IT are tied up, so I do not have the option of creating a function or stored procedure which I appreciate would be the ideal solution.
The situation is that the end user might be using a generic script, when they should be using a specific script for their issue, so I want to create some SQL that detects if they should have gone to a different script using a keyword search.
I have a list of words associated with each script I feel they should be using, for example:
Repair script keywords: repair, broken, chasing
Estate script keywords: dirty, cleaning, garden
What I want to do is to make some SQL that assigns a numerical value of 1 to each instance of these words within the databox '{Script.Details01}', and then works out which set of keywords has the highest tally at the end.
This is what I have tired so far, I know it's likely not working due to the syntax. Sadly the software we are using is pretty vague when giving error messages so it's not much help. We are using aliases of V and D. D is the user display, so what they physically see, V is the value that the system reads and is not seen by the user. The databox which is where the string we are searching from is '{Script.Details01}'. As this information is stored within the software virtually we do not have to use the FROM field as we would do normally when referencing this location.
SELECT 'GO TO DIFFERENT SCRIPT' D, 'GO TO DIFFERENT SCRIPT' V,
CASE WHEN EXISTS(SELECT '{Script.Details01}' WHERE '{Script.Details01}' like '%repair%') THEN 1 ELSE 0 END +
CASE WHEN EXISTS(SELECT '{Script.Details01}' WHERE '{Script.Details01}' like '%broken%') THEN 1 ELSE 0 END +
CASE WHEN EXISTS(SELECT '{Script.Details01}' WHERE '{Script.Details01}' like '%chasing%') THEN 1 ELSE 0 END AS REP
CASE WHEN EXISTS(SELECT '{Script.Details01}' WHERE '{Script.Details01}' like '%dirty%') THEN 1 ELSE 0 END +
CASE WHEN EXISTS(SELECT '{Script.Details01}' WHERE '{Script.Details01}' like '%cleaning%') THEN 1 ELSE 0 END +
CASE WHEN EXISTS(SELECT '{Script.Details01}' WHERE '{Script.Details01}' like '%garden%') THEN 1 ELSE 0 END AS EST
WHERE REP = (SELECT MAX(REP)) AND REP <> 0 AND > EST
OR EST = (SELECT MAX(EST)) AND EST <> 0 AND > REP
Essentially what I'm looking for the code to do is to tell me if there is a higher tally for REP (repair) and EST (estate) or if there are no values registered against either. Apologies if I have not explained this well, there are a few restrictions within the software we are using so trying to explain it as best I can. Any ideas would be greatly appreciated.