SQL Query: How to check if a particular record had more alphabets than numbers and return that

Viewed 91

I am working with Microsoft SQL Server 2014.

I want to display the result if a particular record had more alphabets than numbers with the help of a SQL Query.

For Example:If a table had column 'CustomerName' and it had value "ALeX143ForU"(since it had more alphabets than numbers), then the query should return that particular record.

1 Answers

Bit unusual, but you can try this below logic-

Demo Here

SELECT *
FROM your_table_name
WHERE
-- Below is calculating String LEN only for Alphabet
LEN(
    REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
    your_column_name,'0',''),'1',''),'2',''),'3',''),'4',''),'4',''),'6',''),'7',''),'8',''),'9','')
) 
>
-- Calculate LEN for Integer value only
(
    -- Full string LEN
    LEN(your_column_name) -
    -- LEN for only alphabet
    LEN(
       REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
    your_column_name,'0',''),'1',''),'2',''),'3',''),'4',''),'4',''),'6',''),'7',''),'8',''),'9','')
    )
)
Related