Solved

more than 4 upper case characters in a row

Posted on 2013-12-12
7
331 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
  • 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 68

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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 68

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 68

Accepted Solution

by:
Qlemo earned 500 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

861 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now