SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 select records that contain capital letters
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

maryxu
Starting Member

36 Posts

Posted - 04/08/2008 :  13:44:27  Show Profile  Reply with Quote
how to find capital lettes in a field use query? thanks

TG
Flowing Fount of Yak Knowledge

USA
6059 Posts

Posted - 04/08/2008 :  14:53:12  Show Profile  Reply with Quote
You can use a case sensitive collation like "COLLATE SQL_Latin1_General_CP1_CS_AS" to perform comparisons.

You're going to need to be more specific if you want a solution.
Do you want all rows in a table where a column contains any capital letters?
or where ALL letters are upper case?
Or maybe from a single value you want only the characters that are upper calse alpha characters returned?

This example will return only the row where ALL the letters are upper case:

select	f
from	(
	select 'tg' as f union all
	select 'Tg' union all
	select 'TG'
	) d
where	f COLLATE SQL_Latin1_General_CP1_CS_AS =  upper(f) COLLATE SQL_Latin1_General_CP1_CS_AS



Be One with the Optimizer
TG
Go to Top of Page

hema_sundar
Starting Member

2 Posts

Posted - 04/27/2011 :  05:03:06  Show Profile  Reply with Quote
The answer was quite useful. But is there any way to find the caps in some words or some part of the word.

like China HEALTHCARE INVEStement.
Go to Top of Page

raghuveer125
Constraint Violating Yak Guru

India
283 Posts

Posted - 04/27/2011 :  05:32:12  Show Profile  Reply with Quote
This will help you
I just modified TG query see this he did good
To find all upper case, lower case and single or multiple upper case letter

create table #t(Fname nvarchar(max))
insert into #t
Select 'HI HOW ARE YOU' union all
select 'This is Word' union all
select 'hi India' union all
select 'thinkInda' union all
select 'HI' Union all
select 'India' union all
select 'think'

--To find all lower cases
Select * from #t
where Fname COLLATE SQL_Latin1_General_CP1_CS_AS = lower(Fname) COLLATE SQL_Latin1_General_CP1_CS_AS

--To find all upper cases
select * from #t
where Fname COLLATE SQL_Latin1_General_CP1_CS_AS = upper(Fname) COLLATE SQL_Latin1_General_CP1_CS_AS

--To find only single upper case
select * from #t
except
(Select * from #t
where Fname COLLATE SQL_Latin1_General_CP1_CS_AS = lower(Fname) COLLATE SQL_Latin1_General_CP1_CS_AS
union all
select * from #t
where Fname COLLATE SQL_Latin1_General_CP1_CS_AS = upper(Fname) COLLATE SQL_Latin1_General_CP1_CS_AS
)


Raghu' S

Edited by - raghuveer125 on 04/27/2011 05:34:42
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 04/27/2011 :  06:11:12  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
How about
select * from #t
where Fname COLLATE SQL_Latin1_General_CP1_CS_AS <> lower(Fname) COLLATE SQL_Latin1_General_CP1_CS_AS

That should give entries that contain capital letters.
What do you want to return?


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Edited by - nigelrivett on 04/27/2011 06:11:40
Go to Top of Page

hema_sundar
Starting Member

2 Posts

Posted - 04/27/2011 :  06:39:06  Show Profile  Reply with Quote
Thanks, it was useful
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000