Welcome to Microsoft T-SQL Q&A Forum!
The answer below is a change based on NaomiNNN's answer, maybe it can be done better, I will explain the implementation idea to you:
- First, you need to connect the two tables, and filter out the fields that only satisfy the same code column. At this time, there are 5 records that meet the conditions;
- Find V = the position at this time, which is 15, add 3 to the position of v to get the "previous position, the purpose of this is to find the position of the number in the middle of the two" ;
- Use the difference between the positions to calculate the number between the two "" after v= ;
Please Try the below code: ;with cte
as
(
select t2.id,t1.code,t2.comment ,t1.MaxValue,t1.MinValue,
SUBSTRING (comment, PATINDEX('%V="%',comment) + 3, CHARINDEX('"', comment,PATINDEX('%V="%',comment)+4) - PATINDEX('%V="%',comment) -3)as value
from ##tab1 t1 inner join ##tab2 t2 on t2.code=t1.code )
select id,code,comment from cte
where value not between MinValue and MaxValue
Here is the result:
Best regards,
Bert Zhou
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.