Question

SQL query to rerurn data with CAPS

Asked by: newbie27

Hello experts
I have a table with 1000+ records and I want to extract all the records which has got capital letters in it in SQL SERVER 2005 .

Please can someone advise if I can write some SQL to do so?

Thanks in advance.

Regards
S

SELECT 
      
      [Value]
  FROM [Match]
where [patterid=5] and [value] in captial letters

                                  
1:
2:
3:
4:
5:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-11-03 at 09:15:53ID24867894
Topics

SQL Query Syntax

,

SQL Server 2005

Participating Experts
4
Points
500
Comments
26

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. CAPS Query!!!
    I have a table with city names that are fully capitalized. I want to run a query to only capitalize the first letter of each word like this: NEW YORK SAN DIEGO FARGO CABO DEL SOL *** run query *** New York San Diego Fargo Cabo Del Sol The cities in all caps are in the ...
  2. Convert Capitalized text to lowercase
    I imported text into a table and the text is all capitalized. Can I convert it so that the first letter is Capital and the rest is lower case?
  3. capital letter in sql script
    dumb question Is there an update script that I can change all the data to capital letters(caps lock) in a table it is for legibility rutger

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: lsavidgePosted on 2009-11-03 at 09:23:27ID: 25731251

Here is a run down of the various methods...

http://vyaskn.tripod.com/case_sensitive_search_in_sql_server.htm

Lee

 

by: selva_konguPosted on 2009-11-03 at 09:40:24ID: 25731438

You can change the collation on the fly in your query; example below
SELECT    [Value]  FROM [Match] where [patterid=5] and [value] Latin1_General_CS_AI = [value]

To get a list of collations use the code below
SELECT * FROM fn_helpcollations()

 

by: selva_konguPosted on 2009-11-03 at 09:44:48ID: 25731483

use this function to check the data is upper or lower case

CREATE FUNCTION fnChkAllCaps(@P_String VARCHAR(500))
RETURNS BIT
AS
BEGIN

DECLARE @V_RetValue BIT
DECLARE @V_Position INT

SET @V_Position = 1
SET @V_RetValue = 0  
Loop through all the characters
WHILE @V_Position <= DATALENGTH(@P_String) AND @V_RetValue = 0

BEGIN

     Check if ascii value of the character is between 65 & 90
     Note: Ascii value of A is 65 and Z is 90
     IF ASCII(SUBSTRING(@P_String, @V_Position, 1))
            BETWEEN 65 AND 90
        SELECT @V_RetValue = 0
    ELSE
       SELECT @V_RetValue = 1      
   Move to next character      
   SET @V_Position = @V_Position + 1
END
Return the value
RETURN @V_RetValue
END


SELECT    [Value]  FROM [Match] where [patterid=5] and dbo.fnChkAllCaps([value]) = 0

 

by: newbie27Posted on 2009-11-03 at 09:47:34ID: 25731508

hi

this is giving an error


SELECT    [Value]  FROM [Match] where [patterid=5] and [value] Latin1_General_CS_AI = [value]

error
An expression of non-boolean type specified in a context where a condition is expected, near 'Latin1_General_CS_AI'.

please advise

 

by: selva_konguPosted on 2009-11-03 at 09:49:33ID: 25731526

sorry try the other option, currently i'm not able to check

 

by: aneeshattingalPosted on 2009-11-03 at 09:54:52ID: 25731586

SELECT *
FROM [Match]
WHERE  [patterid=5] and  patindex('%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]%',VALUE COLLATE SQL_Latin1_General_CP1_CS_AS) > 0

 

by: aneeshattingalPosted on 2009-11-03 at 09:55:10ID: 25731590

SELECT *
FROM [Match]
WHERE  patterid=5 and  patindex('%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]%',VALUE COLLATE SQL_Latin1_General_CP1_CS_AS) > 0

 

by: newbie27Posted on 2009-11-03 at 09:56:08ID: 25731602

HI selva_kongu:

THANK YOU SO MUCH FOR THE SNIPPET, I AM NOW GETTING THE RESULT HOWEVER, ITS IGNORING THE SENTENCE...

I MEAN, IF THE [VALUE]= 'JACK' ITS GETTING IT BUT WHEN THE [VALUE]='HAPPY BIRTHDAY JACK'

ITS NOT GETTING IT...

PLEASE CAN YOU ADVISE?

THANKS

 

by: newbie27Posted on 2009-11-03 at 09:58:13ID: 25731624

Hi aneeshattingal,

SELECT *
FROM [PC_Match]
WHERE  
patindex('%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]%',VALUE COLLATE SQL_Latin1_General_CP1_CS_AS) > 0

this has returned all the data ... irrespective of any case...

thanks

 

by: aneeshattingalPosted on 2009-11-03 at 10:01:19ID: 25731654

is that the exact query you tried ?

 

by: aneeshattingalPosted on 2009-11-03 at 10:04:05ID: 25731685

can u run this and return the result

sp_HelpSort

 

by: newbie27Posted on 2009-11-03 at 11:52:58ID: 25732811

yes, i have ran the exact statement as above...

>>sp_HelpSort

Latin1-General, case-insensitive, accent-sensitive, kanatype-insensitive, width-insensitive for Unicode Data, SQL Server Sort Order 52 on Code Page 1252 for non-Unicode Data

 

by: angelIIIPosted on 2009-11-03 at 12:31:01ID: 25733253

you need to "reverse" the logic of the patindex:
you want to find all the rows that have ONLY CAPS (and spaces...)

SELECT *
FROM [PC_Match]
WHERE  
patindex('%^[ABCDEFGHIJKLMNOPQRSTUVWXYZ ]%',VALUE COLLATE SQL_Latin1_General_CP1_CS_AS) = 0

 

by: newbie27Posted on 2009-11-03 at 14:08:37ID: 25734348

Hi angelIII:

Thanks for your input, I have tried with your query and it has returned the same results, all the data but we need rows with CAPS in it....

please advise
thanks

 

by: angelIIIPosted on 2009-11-03 at 14:11:26ID: 25734383

can you please show an example of a row data that is returned, but should not?

 

by: newbie27Posted on 2009-11-03 at 14:15:39ID: 25734427

PLEASE SEE ATTACHED

thanks

35	13	 
36	1	Sonny Pearce
36	2	Have a lovely Twelfth Birthday Sonny!
36	3	Mum, dad and Jake Pearce
36	4	21/09/2009
36	5	N.,J. and J.Pearce
36	6	Alice's Adventures In Wonderland
36	7	ALICERBFZKDTWK
36	8	ALICE
36	9	DANIEL
36	10	REBECCA
36	11	MICHAEL
36	12	SONNY
36	13	JAKE
37	93	SARE-BEAR NICHOLLS
37	94	NO MATTER WHERE YOU ARE, YOU'LL ALWAYS  BE WITH ME IN MY HEART.   LOVE ALWAYS  JUJU xxXXxx
37	95	MONKEY CLAP PRODUCTIONS
37	96	31/10/2009
37	97	JULIE LOUISE HOLT, "THE" JULIE LOUISE HOLT
37	98	The Wonderful Wizard of Oz
37	99	WIZARNGSP7M9LX
37	100	SARE-BEAR
37	101	HARLEY
37	102	SMITH
37	103	JUJU
37	104	SHAZZ
37	105	EMMA-D
38	53	My Darling Rachael
38	54	I hope you don't think I've desecrated a classic!    I know you love this book so much, so I thought I'd give you a chance to play the pivotal role.    This gift is for no reason other than I love you x
38	55	The Amazing Adam
38	56	28/02/1981
38	57	Adam Sharp
38	58	Pride and Prejudice

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:

Select allOpen in new window

 

by: angelIIIPosted on 2009-11-03 at 14:17:56ID: 25734446

is that the data in the table?
if yes, what should be the return for the query?

 

by: newbie27Posted on 2009-11-03 at 14:22:44ID: 25734481

Yes, it is some of the data in the table.

I want to get the result as attached....

meaning all the rows whose [value] in CAPS

thank you

pc_id pattern_id value
=========================
36      7       ALICERBFZKDTWK
36      8       ALICE
36      9       DANIEL
36      10      REBECCA
36      11      MICHAEL
36      12      SONNY
36      13      JAKE
37      93      SARE-BEAR NICHOLLS
37      94      NO MATTER WHERE YOU ARE, YOU'LL ALWAYS  BE WITH ME IN MY HEART.   LOVE ALWAYS  JUJU xxXXxx
37      95      MONKEY CLAP PRODUCTIONS
37      96      31/10/2009
37      97      JULIE LOUISE HOLT, "THE" JULIE LOUISE HOLT
37      98      The Wonderful Wizard of Oz
37      99      WIZARNGSP7M9LX
37      100     SARE-BEAR
37      101     HARLEY
37      102     SMITH
37      103     JUJU
37      104     SHAZZ
37      105     EMMA-D

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:

Select allOpen in new window

 

by: angelIIIPosted on 2009-11-03 at 14:24:32ID: 25734495

should these 2 rows really be returned?
37      94      NO MATTER WHERE YOU ARE, YOU'LL ALWAYS  BE WITH ME IN MY HEART.   LOVE ALWAYS  JUJU xxXXxx
37      98      The Wonderful Wizard of Oz

what about this one:
37      96      31/10/2009
has only digits and slashes?

 

by: newbie27Posted on 2009-11-03 at 14:26:36ID: 25734509

hi angelll

lets narrow down the search to those only with pattern_id= 94

if i get for one pattern then i will do the same for the another 7 different pattern ids...

thanks

 

by: newbie27Posted on 2009-11-03 at 14:28:22ID: 25734527

if i have the data something like this ....

 

36      13      JAKE
37      93      SARE-BEAR NICHOLLS
37      94      NO MATTER WHERE YOU ARE, YOU'LL ALWAYS  BE WITH ME IN MY HEART.   LOVE ALWAYS  JUJU xxXXxx
37      95      MONKEY CLAP PRODUCTIONS
37      96      31/10/2009
37      97      JULIE LOUISE HOLT, "THE" JULIE LOUISE HOLT
37      98      The Wonderful Wizard of Oz
37      99      WIZARNGSP7M9LX
37      100     SARE-BEAR
 
40      93      SARE-BEAR NICHOLLS
40      94      this is the test data
40      95      MONKEY CLAP PRODUCTIONS
40      96      31/10/2009
40      97      JULIE LOUISE HOLT, "THE" JULIE LOUISE HOLT
40      98      The Wonderful Wizard of Oz
40      99      WIZARNGSP7M9LX
40      100     SARE-BEAR

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:

Select allOpen in new window

 

by: angelIIIPosted on 2009-11-03 at 14:28:53ID: 25734534

sorry, but you lost me.

can you please! show the final output you want (for pattern_id = 94) ?

 

by: aneeshattingalPosted on 2009-11-03 at 14:29:54ID: 25734544

so u basically need to return the records with all 'caps'

select * from urTable WHERE  BINARY_CHECKSUM (UPPER(value) )= BINARY_CHECKSUM(value)

 

by: newbie27Posted on 2009-11-03 at 14:32:46ID: 25734571

hi aneeshattingal:

thanks for your query, i think i am almost there ....

this has returned the following result using the following statement

select * from [PC_Match] WHERE  BINARY_CHECKSUM (UPPER(value) )= BINARY_CHECKSUM(value)
and pc_patternid=94

48	94	ENJOY THIS BOOK ALICE
79	94	WITH LOVE ON YOUR BIRTHDAY. XXX
202	94	TO KATE,  WITH LOVE AT CHRISTMAS 2009  LOVE AUNTY CLAIRE AND UNCLE LIAM
220	94	We might be a thousand miles apart in reality, but in our favorite place of fantasy we are together, and now here is the written proof!  I am truely blessed to have met you and I am thankful everyday that a lady called Joanne decided to pen an amazing novel that brought us together!
222	94	 
256	94	FOR MY LITTLE AMBER! HOPE YOU ENJOY READING YOUR SPECIAL ADVENTURE!
284	94	A unique book to love and cherish
286	94	
308	94	
419	94	DEAR FRANCESCA HAVE A WONDERFUL CHRISTMAS.  HAPPY READING.  LOTS OF LOVE  MUMMY, ROBERT, BENJAMIN & GEORGE  X X X X
445	94	WISHING YOU A WONDERFUL CHRISTMAS.THOUGHT YOU WOULD LOVE THIS.HOPE YOU ENJOY READING IT.
482	94	
484	94	THE PICKERING FAMILY BACK TOGETHER AGAIN IN A STORY ESPECIALLY FOR LISA XXX
501	94	
628	94	
823	94	TO A SPECIAL GIRL WHO DESERVES TO HAVE HER OWN STORY WRITTEN ABOUT HER XX
904	94	
907	94	HOPE YOU FIND THE EMERALD CITY
950	94	
955	94	MERRY CHRISTMAS   HOPE YOU ENJOY YOUR ADVENTURES IN OZ!!  LOT'S OF LOVE  TORI, STUART AND LUCY  XXX
978	94	HAPPY CHRISTMAS CAOILFHINN.    WE HOPE YOU ENJOY YOUR SPECIAL BOOK.    ALL OUR LOVE, HUGS AND KISSES    AUNTIE CATE, UNCLE TONY  AND YOUR LITTLE COUSINS  JAK & AOIBH XX
1067	94	

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:

Select allOpen in new window

 

by: aneeshattingalPosted on 2009-11-03 at 19:36:25ID: 25736186


select * from [PC_Match] WHERE CONVERT(varbinary(max), UPPER(value) )= CONVERT(varbinary(max), value)
and pc_patternid=94

 

by: newbie27Posted on 2009-11-04 at 02:46:36ID: 25738017

thanks, that has worked !

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...