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

Article translations Article translations
Article ID: 290921 - View products that this article applies to.
This article was previously published under Q290921
BUG #: 351791 (SHILOH_bugs)
Expand all | Collapse all


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.


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.


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


Use the CAST or CONVERT functions to result in the corrent metadata length; for example:
use pubs
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.
drop table meta


Microsoft has confirmed that this is a problem in SQL Server 2000. This problem was first corrected in SQL Server 2000 Service Pack 1.


To reproduce the problem, execute the following query:
use pubs
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


Article ID: 290921 - Last Review: November 6, 2003 - Revision: 3.2
  • Microsoft SQL Server 2000 Standard Edition
kbbug kbfix kbsqlserv2000sp1fix KB290921

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from