Friday 6 April 2018

How to trick PSQuery to use LIKE and UPPER

Client wants a PSOPRDEFN query that prompts user for OPRID...

Something that still works even if the user tYpEs LikE aN IdiOT or uses a wildcard character (%).


Ok, so your first instinct would be to create a new expression.

But then you realize, you can't use expressions if condition is LIKE.

Click Read More to see how to trick PSQuery to use LIKE and UPPER at the same time...

1. Create a new expression with just 'X'.

2. Create a new criteria and use your 'X' expression on the left side.
On the right side, use

'X' AND A.OPRID LIKE UPPER(:1)

This is how your final criteria should look like.

How that translates in View SQL tab.

And no matter how weird the search word is...

It will still work.

Bonus: You can also throw in LTRIM and RTRIM in there to catch leading and trailing spaces.

1 comment:

  1. Is there any way to automatically add the '%' onto the criteria, so you can just enter 'ABC' and it gets converted to 'ABC%'?

    ReplyDelete