SQL Split character from numbers

Looking to split VFPNO00007654 into VFPNO 00007654
example  2 VSDN00002345 into VSDN 00002345

Any help much appreciated
LVL 4
Mauro CazabonnetSenior Software EngineerAsked:
Who is Participating?
 
ste5anConnect With a Mentor Senior DeveloperCommented:
Use PATINDEX and SUBSTRING:

DECLARE @Sample TABLE
    (
      AlphaNumeric NVARCHAR(255)
    );

INSERT  INTO @Sample
VALUES  ( N'VFPNO00007654' ),
        ( N'VSDN00002345' );

SELECT  S.AlphaNumeric ,
        PATINDEX('%[0-9]%', S.AlphaNumeric) ,
        SUBSTRING(S.AlphaNumeric, 1, PATINDEX('%[0-9]%', S.AlphaNumeric)) ,
        SUBSTRING(S.AlphaNumeric, PATINDEX('%[0-9]%', S.AlphaNumeric), 1024)
FROM    @Sample S;

Open in new window

1
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Are those variables or table columns?
Do you want to split them in 2 variables/columns or add a single space between them?
The rule is to split at the first zero or any number?
0
 
Mauro CazabonnetSenior Software EngineerAuthor Commented:
Stefan,
Awesome thx.......
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.