Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 93
  • Last Modified:

SQL Split character from numbers

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

Any help much appreciated
0
Mauro Cazabonnet
Asked:
Mauro Cazabonnet
1 Solution
 
ste5anSenior 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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now