question

aRookieBIdev avatar image
aRookieBIdev asked

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
sql-server-2012string-functionpatindex
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
aRookieBIdev avatar image
aRookieBIdev answered
declare @x varchar(50) = 'tasfasdfas123' select left(@x,patindex('%[0-9]%',@x+' ')-1 ) alpha ,right(@x,len(@x)-patindex('%[0-9]%',@x+' ')+1) numerics
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.