For example
I have:
PN*BR PN
872*07 872
8445*07 8455
I need a new BR column:
PN*BR PN BR
872*07 872 07
8445*07 8455 07
For example
I have:
PN*BR PN
872*07 872
8445*07 8455
I need a new BR column:
PN*BR PN BR
872*07 872 07
8445*07 8455 07
Here is one way:
select t.*,
replace(replace([PN*BR], PN, ''), '*', '') as BR
from table t
Repeated values are a problem. And now that the question is tagged with a database, I would suggest:
select t.*,
replace([PN*BR], PN + '*', '') as BR
from table t
SELECT LEFT([PN*BR],PATINDEX('%*%',[PN*BR])-1) AS PN,
RIGHT([PN*BR],LEN([PN*BR]) - PATINDEX('%*%',[PN*BR])) AS BR
FROM Table
SELECT t.*,
STUFF([PN*BR], 1, CHARINDEX('*', [PN*BR]), '') BR
FROM <yourtable> t
SELECT SUBSTRING(PN*BR,1,CHARINDEX('*',PN*BR,1)-1) as PN, SUBSTRING(PN*BR,CHARINDEX('*',PN*BR,1)+1,LEN(PN*BR)-CHARINDEX('*',PN*BR,1)) as BR
FROM Table
Answered here: How to split a single column values to multiple column values?
Extract:
SELECT CASE
WHEN name LIKE '% %' THEN LEFT(name, Charindex(' ', name) - 1)
ELSE name
END,
CASE
WHEN name LIKE '% %' THEN RIGHT(name, Charindex(' ', Reverse(name)) - 1)
END
FROM YourTable