Solved

SQL Split character from numbers

Posted on 2016-11-29
3
16 Views
Last Modified: 2016-11-29
Looking to split VFPNO00007654 into VFPNO 00007654
example  2 VSDN00002345 into VSDN 00002345

Any help much appreciated
0
Comment
Question by:mcazabonnet
3 Comments
 
LVL 32

Accepted Solution

by:
ste5an earned 500 total points
ID: 41905842
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
 
LVL 45

Expert Comment

by:Vitor Montalvão
ID: 41905845
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
 
LVL 4

Author Closing Comment

by:mcazabonnet
ID: 41905876
Stefan,
Awesome thx.......
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now