Length function counts only trailing spaces in a string

Database
KVB
Enthusiast

Length function counts only trailing spaces in a string

SEL LENGTH('   VENKAT   ')

I have 3 spaces before and after the name,it returns 9 as it is 12 character string.

When used with CHAR_LENGTH('   VENKAT   ') it returns 12

As the length measures the strings in the form of BYTES and the CHAR_LENGTH measures the string inthe form of characters.

Why the length is not couting the right side spaces?

Regards

KVB

1 REPLY
Junior Supporter

Re: Length function counts only trailing spaces in a string

Strange:

 BTEQ -- Enter your SQL request or BTEQ command:
SELECT LENGTH(' VENKAT ') "Length";

*** Query completed. One row found. One column returned.
*** Total elapsed time was 1 second.

Length
----------------------------------------
12

BTEQ -- Enter your SQL request or BTEQ command:
SELECT CHAR_LENGTH(' VENKAT ') "CharLength";

*** Query completed. One row found. One column returned.
*** Total elapsed time was 1 second.

CharLength
-----------
12

¿Maybe it's SQLAssistant through ODBC?

Cheers.

Carlos.