Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL server query to find values containing only special chars?

I need to write a query to pull values from a column containing only special characters. I know that the below query would give me all values containing at least one special char but that is not what I need. Can anybody help me please?

SAMPLE DATA -

    ORG
    ^^567
    ~423
    %^&/
    329

I need to write a query which will return only %^&/ from the above sample data.

SELECT org
FROM table_A
WHERE org like '%[^a-Z0-9]%'
like image 893
Reeya Oberoi Avatar asked Dec 12 '25 16:12

Reeya Oberoi


1 Answers

Try this

SELECT org
FROM table_A
WHERE org Not like '%[a-Z0-9]%'

Demo

SELECT org
FROM   (SELECT '1asdasdf' org
        UNION
        SELECT '$asd#'
        UNION
        SELECT '$^%$%') a
WHERE  org Not Like '%[a-Z0-9]%' 

Result: $^%$%

like image 117
Pரதீப் Avatar answered Dec 15 '25 09:12

Pரதீப்



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!