Let me start by saing I totally agree with Marc_s's comment - Never ever store multiple values in a single column.
For more information, read Is storing a delimited list in a database column really that bad?, where you will see a lot of reasons why the answer to this question is Absolutly yes!
Now, assuming you can't change the database structure, here is one way to do it using Left
and Right
with charIndex
Create and populate sample table (Please save us this step in your future questions)
DECLARE @T AS TABLE
(
Col varchar(10)
)
INSERT INTO @T VALUES
('a|b'),
('ab|cd'),
('abc|def'),
('abcd|efgh'),
('abcde|fghi')
The Query:
SELECT Col,
LEFT(Col, CHARINDEX('|', Col)-1) As Part1,
RIGHT(Col, LEN(Col) - CHARINDEX('|', Col)) As Part2
FROM @T
Results:
Col Part1 Part2
a|b a b
ab|cd ab cd
abc|def abc def
abcd|efgh abcd efgh
abcde|fghi abcde fghi