Re: LENGTH function and trailing spaces
Posted in 1995
Topics: SQL Development & Query Writing, Data Types & Schema Design
Kirk Bradley wrote (edited): >: : The question is (still) >: : how can I get the length as stored by the application program >: : via a SQL statement. The answer appears to be that you cannot >: : and that's fine with me. To which Zdeno Miklas responded (edited): >: [The] answer to your question was posted in this >: thread. This statement returns length of varchar column >: including trailing spaces. >: >: SELECT LENGTH(varcharcol || "x") - 1 FROM yourtable To which Kirk Bradley responded (edited): >Sorry.. what if the varchar column is the maximum length already. >Concatenating another character to it will not work. I need >a general solution. Wow, this seems pretty easy. Maybe I just don't get it. From what I can see, (assuming the above statement is legal, which I can not test), the above SELECT statement has nothing to do with whether the varchar column is the maximum length. It'll work if it is and it'll work if it's not. It looks to me to be a general solution to the question posed. I am curious, though, what if varcharcol is NULL? What happens when you catenate a string to a NULL? What if you catenate a character to a NULL? If the result is a NULL, is the LENGTH 0? or NULL? or something else? Do these answers vary if done in a program, as opposed to mid-SQL? Thanks, rodney