Re: Collation....
From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 10/13/04
- Next message: Rhino: "Re: How to specify column header titles in a SQL CREATE TABLE statement?"
- Previous message: Louis Davidson: "Re: securing a database deployment"
- In reply to: John Smith: "Collation...."
- Next in thread: John Smith: "Re: Collation...."
- Reply: John Smith: "Re: Collation...."
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 13 Oct 2004 22:09:02 +0200
On Wed, 13 Oct 2004 09:39:30 -0700, John Smith wrote:
>When I run a query I want to differentiate between the data "E" and "E ".
Hi John,
When you use fixed-length columns (or variables), you can't. Store "E" in
a char(5) or nchar(5) and it will be padded with spaces to "E ". Use
the same datatype to store "E " and it will be padded to "E " as well.
There's no way to tell them apart.
If you use varying-length (varchar or nvarchar), trailing spaces will be
retained. However, on comparison the shorter string will be padded to
match the length of the other string. So while "E " and "E" are stored
exactly as this, the shorter ("E") is still padded to "E " before the
comparison is made.
The workaround is to concatenate something in the comparison. Instead of
using "WHERE Col01 = Col02", you use "WHERE Col01 + 'Q' = Col02 + 'Q'".
This will change the strings to be compared to "E Q" and "EQ"; after
padding the shorter one to match the other one's length, they'll still be
different ("E Q" vs "EQ ").
The downside of this is that an index on Col01 or Col02 (if it exists) can
now no longer be used for the query.
Best, Hugo
-- (Remove _NO_ and _SPAM_ to get my e-mail address)
- Next message: Rhino: "Re: How to specify column header titles in a SQL CREATE TABLE statement?"
- Previous message: Louis Davidson: "Re: securing a database deployment"
- In reply to: John Smith: "Collation...."
- Next in thread: John Smith: "Re: Collation...."
- Reply: John Smith: "Re: Collation...."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|