I have a table with different columns. One of them is Message. I want to check multiple patterns using like in this case.
For a start position here is a simple patterns:
DECLARE @pattern VARCHAR(50) = '%|35=[A,D]|%';
For matching this pattern, I use this query:
SELECT Logid 'LogId', 'Message' Message
FROM Messages
WHERE LogId >= 1000 AND
(m.Message like @pattern);
And it is an example of Message content:
|8=FIX.4.4|9=70|35=A|34=1|10=008|
Now I want to check a complex pattern, which is:
DECLARE @pattern VARCHAR(50) = '%|35=[A,D]|% %|34=[1]|%';
It means that we need to have a message with %|35=[A,D]|% AND %|34=[1]|%. I need to match with a complex pattern with n parts which there is a space between conditions. The previous example is a condition with to statement.
So, first of all, I need to create a list of conditions by splitting pattern and check all of the conditions and make a simple AND between results. I would be glad if I can do that. The last point is that the pattern is an input of a stored procedure.
@pattern
always have 2 patterns, or can it be 1, 2, 3, or more? Will the patterns always be separated by a space, and no space could ever be inside a pattern? Will the patterns always be enclosed in leading/trailing wildcards? – Aaron Bertrand♦ Feb 15 '17 at 4:56'single quotes'
- this is deprecated, and good riddance, because they make it very cumbersome to tell string constants from column aliases. When necessary, use[square brackets]
or - if you like causing readers pain -"double quotes"
. – Aaron Bertrand♦ Feb 15 '17 at 5:40