Reputation: 1055
I have a column that contains values similar to:
034004
034010
06012AB
06012C
06012D
06012P
06026C
06026P
Is there any way to separate or split these in two separate columns as numbers and letters? Does it matter that not all numbers contain letters?
I am using SQL Server Management Studio 2005
Cheers in advance for anything that can point me in the right direct
Upvotes: 2
Views: 5138
Reputation: 453908
Assuming it is always one group of numbers then (possibly) one group of letters
SELECT SUBSTRING(YourCol, 0, P),
SUBSTRING(YourCol, P, 8000)
FROM YourTable
CROSS APPLY(SELECT PATINDEX('%[^0-9]%', YourCol + 'A')) Split(P)
Upvotes: 5