Link to home
Start Free TrialLog in
Avatar of databarracks
databarracks

asked on

MSSQL syntax to get all text left of first non-alphanumeric character

Hi Guys,

Does anyone know the syntax in MSSQL to  get all the characters left from the first non-alphanumeric character:

What I have so far is below:

The LABEL value is 'Joe Bloggs [Duplicate - do not use]'

SUBSTRING([LABEL],0,CHARINDEX('[',[LABEL],0))

Open in new window


This yields  'Joe Bloggs ' which is ok but the issue is that someone could put any other character therefore it wouldn't work if someone puts ^ or / etc.

Could someone please kindly help me withthis?
Avatar of databarracks
databarracks

ASKER

Actually I think I can do this:

LTRIM(RTRIM(LEFT([LABEL], PATINDEX('%[^0-9A-Za-z]%', [LABEL]) - 1)))

Open in new window

But only issues is I do want to permit spaces?
ASKER CERTIFIED SOLUTION
Avatar of databarracks
databarracks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Figured it out myself. Thanks anyway