July 18, 2018 at 7:15 am
Dear all
In my table one column i have records in following formets
mat201
mat202
sci12
science203
In this above value i want to segregate two different column like a
MAT 201
MAT 202
SCI 12
SCIENCE 201
Please help me above result
July 18, 2018 at 7:27 am
vs.satheesh - Wednesday, July 18, 2018 7:15 AMDear allIn my table one column i have records in following formets
mat201
mat202
sci12
science203In this above value i want to segregate two different column like a
MAT 201
MAT 202
SCI 12
SCIENCE 201Please help me above result
You could try to do it with substring and patindex. It's not that hard to do.
July 18, 2018 at 7:33 am
select upper (substring(col,0,patindex('%[0-9]%',col))+' '+substring(col,patindex('%[0-9]%',@col,99))
from your table
***The first step is always the hardest *******
July 19, 2018 at 2:15 pm
SGT_squeequal - Wednesday, July 18, 2018 7:33 AMselect upper (substring(col,0,patindex('%[0-9]%',col))+' '+substring(col,patindex('%[0-9]%',@col,99))
from your table
Almost, but not quite. OP is looking for separate columns, whereas your solution just adds a space in the middle.
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
July 19, 2018 at 2:26 pm
Does this help?
DECLARE @TestTable TABLE (
DataCol VARCHAR(32)
);
INSERT INTO @TestTable
VALUES
('mat201')
,('mat202')
,('sci12')
,('science203');
SELECT
[tt].[DataCol]
, PATINDEX('%[0-9]%',[tt].[DataCol])
, LEFT([tt].[DataCol],PATINDEX('%[0-9]%',[tt].[DataCol]) - 1)
, SUBSTRING([tt].[DataCol], PATINDEX('%[0-9]%',[tt].[DataCol]), DATALENGTH([tt].[DataCol]))
FROM @TestTable AS [tt];
August 3, 2018 at 5:11 am
sgmunson - Thursday, July 19, 2018 2:15 PMSGT_squeequal - Wednesday, July 18, 2018 7:33 AMselect upper (substring(col,0,patindex('%[0-9]%',col))+' '+substring(col,patindex('%[0-9]%',@col,99))
from your tableAlmost, but not quite. OP is looking for separate columns, whereas your solution just adds a space in the middle.
Arr yes, i was looking at his results and returning the data to match instead of splitting the string
***The first step is always the hardest *******
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply