Select the alpha prefix from a column of values

Created by Jeremy Burgess, Modified on Tue, 11 Oct, 2022 at 1:38 PM by Jeremy Burgess

Symptoms

You have been given a list of values in a SQL table and wish to extract the alpha prefix, e.g. "INV123, CASE001, TICKET99" -> "INV, CASE, TICKET"

Cause

n/a

Resolution


SELECT col,
  CASE 
    WHEN col LIKE '[A-Z]%' THEN LEFT(col, PATINDEX('%[^A-Za-z]%', col) - 1)
    ELSE '' 
  END AS alpha_prefix
FROM table

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article