Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to split the column into multiple columns using delimeter in SQL server?

I have below column in my table

enter image description here

I would like to split the column using decimeter ‘-‘ and create a new column in SQL Server.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Required output

enter image description here

I used parsename in the query but no success.

select 
ID,
PARSENAME(ID,'-', 1) AS EmployeeID from timeus;

I checked other posts but not able to solve it.

Can anyone advise how to to split in SQL server?

>Solution :

You can use this script to split the data:

CREATE TABLE dbo.NotProvided
(
    Category NVARCHAR(50)
);
GO

INSERT INTO dbo.NotProvided
(
    Category
)
VALUES
('103-Local IT-HHH'),
('102-HDHD-2737'),
('104-HHFY-XXX');


SELECT *,
       LEFT(Category, CHARINDEX('-', Category) - 1) as Id
FROM dbo.NotProvided;

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading