Please consider the following SQL Fiddle: http://sqlfiddle.com/#!3/9d4fc/3
I have 3 documents:
('id1', 'lorem ipsum dolor dog'),
('id2', 'the cat jumps over the lazy dog'),
('id3', 'i have no clue what to write');
I want to dynamically search these documents for needles:
('a', 'dog'),
('b', 'dolor'),
('c', 'write');
The results I need would be table tmp_auditlog_results
looking like
doc needle string
---------------------------------------------
id1 dog lorem ipsum dolor dog
id2 dog the cat jumps over the lazy dog
id1 dolor lorem ipsum dolor dog
id3 write i have no clue what to write
I got confused by the dynamic query adding to the result table. Could you please have a look how I can get this result from the result I have now? Any help would be appreciated.
4条答案
按热度按时间olmpazwi1#
You don't need any dynamic code. You can use
CHARINDEX
jmp7cifd2#
Replace the select statement:
with following statement:
x6yk4ghg3#
The answer from podiluska needed some renaming of column names. So i created this example starting from his query
Given these Tables
And these records
This query
returns this result
See this demo fiddle this matches the expected query result
92vpleto4#