Field with mixed case characters

  • Does anybody have a script to check if a character field in a table has mixed case characters, e.g. AbCdE ?

  •  CREATE FUNCTION dbo.udf_IsMixedChars(@str varchar(4000))

     Returns int

     AS

     BEGIN

    -- This Function Assumes the Existence of a Numbers Table

    -- CREATE TABLE Numbers(Number int) Filled accordingly!

     DECLARE @Result int

    If Exists(

     Select 1

     From Numbers

     Where Number <= Len(@str)

     and  ASCII(Substring( @str, Number,1)) between 65 and 90

    )

    and

    Exists ( Select 1

     From Numbers

     Where Number <= Len(@str)

     and  ASCII(Substring( @str, Number,1)) between 97 and 122

    )

    SET @Result = 1

    ELse

    SET @Result = 0

    RETURN @Result

    END

    Then Use the Fuction as

    SELECT *

    FROM TableName

    Where dbo.udf_IsMixedChars(fld) = 1

     

    HTH

     


    * Noel

  • That's fantastic! Many thanks...

  • No need for a function.  If the column is longer than 30 characters, then adjust the length of the varbinary type being casted.

    SELECT CASE WHEN CAST(Col AS varbinary)=CAST(UPPER(Col) AS varbinary) OR CAST(Col AS varbinary)=CAST(LOWER(Col) AS varbinary) THEN 'No' ELSE 'Yes' END



    --Jonathan

  • That's even better Jonathan, Many thanks!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply