Skip to content
Advertisement

How can I output text until it is ascii in SQL?

How can I output text until it is ascii in SQL?

Here is what I am trying to do:

But in the end I am getting an empty string. Why? What am I missing here?

I am expecting the value of the @output to be 'text' in the end of the script.

UPDATE

If I update the script to the

It will work as expected. But here I just shrinked the set from all printable ascii characters to only small letters. Why does the shrinked set [a-b] include the text characters and the extended set [ -~] does not?

Advertisement

Answer

A space is not a valid range delimiter so LIKE [ -~] will not work. That becomes a test for those three characters only.

You could check the ASCII code directly, rather than using LIKE:

demo

Side note: It’s possible to get unexpected results with LIKE ranges because the comparison is collation-aware.


Answer copied from the duplicate question on Database Administrators

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement