I am trying to select payment plans for a specific t开发者_如何学编程erm from my database. The problem is that my pay_plan field is multivalued, and is set up like this: UTAD*00000*2010SP. I want to match up the specific terms like so:
stmt = conn.prepareStatement("SELECT person FROM schema.payments WHERE pay_plan = ?");
stmt.setString(1, term);
Is there anyway to only match the characters after the final *, or is there any other way to go about this?
WHERE
pay_plan LIKE '%*%*' + @MySearchValue;
This means you'll match only the last bit and assume you always have abc*123*wanted
Note: an index will be ignored because of the leading %
so you'll have to accept poor performance as a consequence of un-normalised data
Try last index of * and then do a substring in the query.
精彩评论