SQL does my head in
-
LEN (Transact-SQL) Returns the number of characters of the specified string expression, excluding trailing blanks So
> print len('hello')
5
and
> print len(' ')
0
Hands up who has ever noticed the "excluding trailing blanks" bit? Up until an hour ago, not me. Which boggles my mind.
cheers Chris Maunder
Alas, I just got smacked by this today even though I know not to trust LEN. In this case, though I was using
VARBINARY(16)
to hold binary IP addresses -- and testing the length to determine IPv4 vs IPv6. And today someone reported that it fails for IP addresses where the last byte is 32. :sigh: -
Yes - I understand the function and how it works. My point was that I'd missed that tiny little proviso. For years. It shocked me. Storing padding data inside a database? Please no. That's awful.
cheers Chris Maunder