Solved

SQL Split character from numbers

Posted on 2016-11-29
3
39 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 33

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 47

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

770 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