FIX: UPPER and LOWER Functions Return Metadata Length as if DBCS Were Used

This article was previously published under Q290921
This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 351791 (SHILOH_bugs)
SYMPTOMS
When the UPPER or LOWER function is used on a column, the result set will have metadata that is twice the length of the string. This is the expected behavior on a double-byte character set (DBCS) collation, which could potentially have 2 bytes per character and where the number of bytes for a character could change based on the case. However, it is not expected behavior for single-byte character set (SBCS) collations.
CAUSE
The UPPER and LOWER functions assume that the number of bytes in the result set could always be twice the number of characters, even in an SBCS environment.
RESOLUTION
To resolve this problem, obtain the latest service pack for SQL Server 2000. For additional information, click the following article number to view the article in theMicrosoft Knowledge Base:
290211 INF: How to Obtain the Latest SQL Server 2000 Service Pack
WORKAROUND
Use the CAST or CONVERT functions to result in the corrent metadata length; for example:
use pubsgoselect CAST(LOWER('abc') as char(3)) as COL1 into metaselect COL_LENGTH('meta', 'COL1') as 'Column Length'--COL_LENGTH returns a value of 3.--Without the CAST function, 6 would be returned instead.godrop table meta				
STATUS
Microsoft has confirmed that this is a problem in SQL Server 2000. This problem was first corrected in SQL Server 2000 Service Pack 1.
MORE INFORMATION
To reproduce the problem, execute the following query:
use pubsgoselect 'abc' as COL1 into metaokselect COL_LENGTH('metaok', 'COL1') as 'Column Length'--This returns a value of 3.select LOWER('abc') as COL1 into metanotokselect COL_LENGTH('metanotok', 'COL1') as 'Column Length'--This returns a value of 6 and should be a value of 3 in an SBCS environment.drop table metaokdrop table metanotok				
Properties

Article ID: 290921 - Last Review: 01/16/2015 21:50:32 - Revision: 3.2

  • Microsoft SQL Server 2000 Standard Edition
  • kbnosurvey kbarchive kbbug kbfix kbsqlserv2000sp1fix KB290921
Feedback