Solved

How to find SQL fields in all CAPS

Posted on 2010-11-24
6
851 Views
Last Modified: 2012-05-10
One of the tables in my SQL database has a field that is, at times, being populated by a third-party software program.  It is populating this field in all caps.  Is there a way to do a query of this field to find instances where entire words are in all caps?  
0
Comment
Question by:lulichk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34209321

SELECT *
FROM tblName
WHERE column_name = UPPER(column_name)

Open in new window

0
 
LVL 17

Expert Comment

by:pssandhu
ID: 34209381
Actually it depends on your current sql servers collation. To use a case sensitive coallation, you can use that in your select statement. The following examples will return records from the table where the whole value is in UPPER CASE.

CREATE TABLE #t (n  VARCHAR(20))

insert into #t(n) Values ('TEST')
insert into #t(n) Values ('zing')

Select *
From
(
Select *,
         CASE WHEN n COLLATE SQL_Latin1_General_CP1_CS_AS = LOWER(n) then 1 else 0 END Val
From #t ) m
Where Val = 0

Hope this helps

P.

0
 
LVL 17

Expert Comment

by:pssandhu
ID: 34209427
Oops.. missed one important check. The value in the field could also be in PROPER CASE, meaning the first alphabet of the word could be capitalised and the rest of the body will be in LOWER CASE. So, in this case please refer to this example:
CREATE TABLE #t (n  VARCHAR(20))

insert into #t(n) Values ('Vick')
INSERT INTO #t(n) Values ('TEST')
insert into #t(n) Values ('zing')

Select * 
From
	(
		Select	*, 
				CASE WHEN RIGHT(n, Len(n)-1) COLLATE SQL_Latin1_General_CP1_CS_AS = LOWER(RIGHT(n, Len(n)-1)) then 1 
					 ELSE 0 
				END Val
		From #t 
	) m
Where Val = 0

DROP TABLE #t

Open in new window

0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 16

Accepted Solution

by:
EvilPostIt earned 50 total points
ID: 34211247
If your collation is not case sensitive then you can do the following

SELECT *
FROM tblName
WHERE column_name COLLATE Latin1_General_CS_AS= UPPER(column_name)

Obviously you can change the collation to the case senitive version of the one that you are currently using.
0
 

Author Comment

by:lulichk
ID: 34230639
Thanks for your responses.  This is my first time I've posted a question and I'm very grateful for the help.  
0
 
LVL 16

Expert Comment

by:EvilPostIt
ID: 34230649
No probs, let me know if i can further assist.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question