?
Solved

more than 4 upper case characters in a row

Posted on 2013-12-12
7
Medium Priority
?
345 Views
Last Modified: 2013-12-13
Experts,

For SQL Server 2012 -- if SQL Server version matters in this case.

I have a unique situation where I need to search a field to check for instance where there are more that 3 upper case characters in a row.

If the value in the column is MedicalRecordCD, I wouldn't want that.
If the value in the column is PatientPLNNumber, I would want that to be returned.

Any assistance is appreciated.
0
Comment
Question by:jvoconnell
[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
  • 3
  • 3
7 Comments
 
LVL 19

Expert Comment

by:jss1199
ID: 39714828
There is no function within SQL to count uppercase letters.  You can create one using the below code.

You could then do WHERE dbo.CountUpperCase (PatientPLNNumber) > 4

CREATE FUNCTION CountUpperCase
(
    @input nvarchar(50)
)
RETURNS int
AS
BEGIN

    declare @len int
    declare @i int
    declare @count int
    declare @ascii int

    set @len = len(@input)
    set @i = 1
    set @count = 0

    while @i <= @len
    begin

        set @ascii = ascii(substring(@input, @i, 1))

        if @ascii >= 65 and @ascii <= 90
        begin
            set @count = @count +1
        end

        set @i = @i + 1

    end

    return @count

END

Open in new window

0
 
LVL 70

Expert Comment

by:Qlemo
ID: 39715448
Like could be used, too:
... where field collate Latin1_General_CS_AS like '%[A-Z][A-Z][A-Z][A-Z]%'

Open in new window

0
 
LVL 1

Author Comment

by:jvoconnell
ID: 39716758
Thank you for your assistance. Looking back at my post, I think I definatley could have been clearer...and I apologize.
This fn is close. It does give a count of all upper case characters within the field. I need it to return those where there are >= 4 Consecutive upper case characters

So 'MedicalRecordCD' would not be valid as the 4 ucase are not consecutive
PatientPLNNumber would be valid as it does have 4 consecutive ucase chars "PLNN"

Once again, I apologize for putting you down the wrong path.
I will see if I am able to modify this function to get it to return the desired output.

Thank you.
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 70

Expert Comment

by:Qlemo
ID: 39716801
Did you try the LIKE approach? It should check exactly for that.
0
 
LVL 1

Author Comment

by:jvoconnell
ID: 39716921
Hello, I did try a variation of both suggestions.


SELECT DISTINCT ColumnNM
FROM ColumnBASE
WHERE CountUpperCase(COLUMNNM) > 3
AND SourceSystemNM = 'PAYERSTAGE'
and COLUMNNM collate Latin1_General_CS_AS like '%[A-Z][A-Z][A-Z][A-Z]%'


SELECT DISTINCT ColumnNM
FROM ColumnBASE
WHERE  SourceSystemNM = 'PAYERSTAGE'
and COLUMNNM collate Latin1_General_CS_AS like '%[A-Z][A-Z][A-Z][A-Z]%'

I am still getting values back  such as   --> ActualCostAMT

...side note. I know this request may sound somewhat foolish. The background is we are implementing a new DW and there are strict naming conventions we have been asked to follow.
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 39717003
That was supposed to work, but obviously the sort order still gets in the way. If we just do Binary compare, it works:
SELECT DISTINCT ColumnNM
FROM ColumnBASE
WHERE  SourceSystemNM = 'PAYERSTAGE'
and COLUMNNM collate Latin1_General_BIN like '%[A-Z][A-Z][A-Z][A-Z]%'

Open in new window

0
 
LVL 1

Author Closing Comment

by:jvoconnell
ID: 39717040
Genius! This site is the best by far.
Thank you both for your efforts.
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

777 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