Microsoft KB Archive/290921

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

Article ID: 290921

Article Last Modified on 11/6/2003

-

APPLIES TO


 * Microsoft SQL Server 2000 Standard Edition

-



This article was previously published under Q290921



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 the Microsoft 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 pubs go select CAST(LOWER('abc') as char(3)) as COL1 into meta select COL_LENGTH('meta', 'COL1') as 'Column Length' --COL_LENGTH returns a value of 3. --Without the CAST function, 6 would be returned instead. go drop 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 pubs go select 'abc' as COL1 into metaok select COL_LENGTH('metaok', 'COL1') as 'Column Length' --This returns a value of 3.

select LOWER('abc') as COL1 into metanotok select 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 metaok drop table metanotok

Keywords: kbbug kbfix kbsqlserv2000sp1fix KB290921

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.