x

SQL Split String into non numeric and numerics

Hi ,

I have certain values such as 'Test123' , 'a3456' , 'cgf999' Which i need to split into string and numerics in sql server 2012.

Examples:

'Test123' -> var1 = Test , var2 = 123

'a3456' -> var1 = a, var2 = 3456

'cgf999' -> var1 = cgf, var2= 999

Thanks Kannan

more ▼

asked Jun 28, 2016 at 07:45 PM in Default

avatar image

aRookieBIdev
2.8k 56 65 71

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

declare @x varchar(50) = 'tasfasdfas123'

select left(@x,patindex('%[0-9]%',@x+' ')-1 ) alpha ,right(@x,len(@x)-patindex('%[0-9]%',@x+' ')+1) numerics

more ▼

answered Jun 28, 2016 at 07:55 PM

avatar image

aRookieBIdev
2.8k 56 65 71

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x411
x12
x6

asked: Jun 28, 2016 at 07:45 PM

Seen: 54 times

Last Updated: Jun 28, 2016 at 07:55 PM

Copyright 2018 Redgate Software. Privacy Policy