Re: SQL Humor

From: Hugo Kornelis <hugo_at_pe_NO_rFact.in_SPAM_fo>
Date: Sat, 20 Aug 2005 00:43:09 +0200
Message-ID: <1sncg1dmkm4feh3c1k2915f1ips2lmr8re_at_4ax.com>


On Fri, 19 Aug 2005 10:49:59 -0400, JT wrote:

>Perhaps I'm misreading your point, but it's data in a Char column that
>typically contains trailing blanks that need a Trim. A VarChar won't contain
>extraneous blanks unless the developer explicitly includes them in the
>value.

Hi JT,

I think that Joe refers to the ANSI comparison rules for char and varchar:

  • Comparing two char (assume same length): Do character by character compare.
  • Comparing two varchar: First, find if actual length (not maximum length!) is different. Then, pad shortest string with spaces until it's just as long as the longest string. Finally, do character by character compare of longest string to padded version of shortest string.

For comparison of char with different length, padding is also required, but this padding is independent of the actual data; it's the same for each row and the amount of padding can be determined in the compile phase. (But in joins, you should not compare two different-length char columns anyway!)

Best, Hugo

-- 

(Remove _NO_ and _SPAM_ to get my e-mail address)
Received on Sat Aug 20 2005 - 00:43:09 CEST

Original text of this message