I’m having a dumb moment and forgetting how to ach...
# suiteql
j
I’m having a dumb moment and forgetting how to achieve something in SQL. Let’s say I have a custom record type customrecord_my_record and one of these records has the name “DEF GHI JKL” I want to be able to accept a keyword, e.g. “GHI” or “ABC DEF GHI JKL MNO”, store it in a variable, and run a SQL to have it match my record. Both these keyword examples would be considered a match: it should match if the keyword is a substring of the name or if the name is a substring of the keyword. I can do “keyword is a substring of the name” fairly easily: let sql = “SELECT * FROM customrecord_my_record WHERE name LIKE ‘%” + keyword + “%‘“; How do I also make it match the latter? Something like let sql = “SELECT * FROM customrecord_my_record WHERE name LIKE ‘%” + keyword + “%’ OR ‘%’ || name || ‘%’ LIKE ‘” + keyword + “’”;
e
Without the variable placeholder, this query works for me SELECT name FROM customrecord_my_record WHERE name LIKE '%LDP151%' OR 'LDP152' like name ||'%'
j
what is the value in ‘name’ in your example?
you’ve got LDP151 and LDP152 so I’m not sure if I’m interpreting your example correctly, should those be the same?
never mind, I think I can use
INSTR()
instead
z
It is good practice to put conditions in brackets where (condition1) OR (condition2)
especially if you have a complex boolean formula ( (condition1) OR (condition2) ) AND (condition3) it is not the same as condition1 OR condition2 AND condition3