UPPER and LOWER functions

gudii9
gudii9 used Ask the Experts™
on
SELECT UPPER(COLUMN1)
FROM SCHEMA1.TABLE1

SELECT UPPER(COLUMN2)
FROM SCHEMA2.TABLE2

i have 100 records in column 1 and column 2 with roughly half capitol words(HONDA etc.) and rest of half small words(nissan etc.)

when i do UPPER character function

i expected to see 50 records with values like NISSAN


when i do LOWER character function
i expected to see 50 records with values like honda

but i got only 2 records.

can you please advise how to fix this
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi gudii,

Neither the UPPER nor LOWER function should have any impact on the number of rows selected (unless used as part of the filter).

What do you get when you execute

  SELECT column1, UPPER(column1), LOWER(column1) from schema1.table1;
and/or
  SELECT column2, UPPER(column2), LOWER(column2) from schema2.table2;
awking00Information Technology Specialist
Commented:
select column1 from schema1.table1
where column1 = upper(column1);

select column2 from schema2.table2
where column2 = upper(column2);

select column1 from schema1.table1
where column1 = lower(column1);

select column2 from schema2.table2
where column2 = lower(column2);
SujithData Architect

Commented:
>> but i got only 2 records.
what is the complete query that you are executing?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Mark WillsTopic Advisor, Page Editor
Distinguished Expert 2018
Commented:
And which Database Server ?

And what collation ?

And what datatype ?

Sometimes (depending on the above) you might have to convert to varchar first


e.g.

SELECT UPPER(cast(COLUMN1 as varchar(100))), LOWER(cast(COLUMN1 as varchar(100)))  
FROM SCHEMA1.TABLE1

SELECT UPPER(cast(COLUMN2 as varchar(100))) , LOWER(cast(COLUMN2 as varchar(100)))
FROM SCHEMA2.TABLE2

(And would like to see results if both columns are same case)
awking00Information Technology Specialist

Commented:
Can you provide [some sample] data for columns 1 and 2 in tables schema1.table1 and schema2.table2 and what you expect as output?
Most Valuable Expert 2012
Distinguished Expert 2018
Commented:
As others have suggested, I can only guess at what you actually mean.

After having read your question about 10 times, I have a slightly different idea about what you are trying to do.

If you want to select only the records what are ALL upper or lower case try this:
select count(*) from SCHEMA1.TABLE1 where upper(column1)=column1;
select count(*) from SCHEMA2.TABLE2 where upper(column2)=column2;
Topic Advisor, Page Editor
Distinguished Expert 2018
Commented:
@slightwv,

in SQL Server you would have to add a case sensitive collation to that clause e.g:

select * from SCHEMA1.TABLE1 where upper(column1)=column1 COLLATE SQL_Latin1_General_Cp1_CS_AS

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial