Hi,
How can I get the out below? I tried this SQL script but it's now working. Any help is appreciated.
SELECT PersonID,
[ProductCode] = SUBSTRING(ProductCode,CHARINDEX('/',ProductCode,
CHARINDEX('/',ProductCode, CHARINDEX('/',ProductCode,
CHARINDEX('/',ProductCode, CHARINDEX('/',ProductCode,
CHARINDEX('/',ProductCode)+1)+1)+1)+1) + 1)+1,
DATALENGTH(ProductCode) - CHARINDEX('/',ProductCode,
CHARINDEX('/',ProductCode)+1) -
CHARINDEX('/',REVERSE(ProductCode))-1 -
CHARINDEX('/',REVERSE(ProductCode))-1 -
CHARINDEX('/',REVERSE(ProductCode))-1)
FROM Temp_Product
CREATE TABLE Temp_Product (
PersonID int,
ProductCode varchar(256),
);
INSERT INTO Temp_Product (PersonID, ProductCode)
VALUES ('234', 'Organitation/My Companies/company ABC/My company divisoin/my company place/department/place of work 234/678/98as/sdfd45679'),
('567', 'Organitation/My Companies/company ABC/My company divisoin 34/my company place 23/department/place of work 433/678/58asu/sdfd45679'),
('876', 'Organitation/My Companies/company ABC/My company divisoin 56/my company place 54/department/place of work 7654/455/68as/sdvd45679'),
('543', 'Organitation/My Companies/company ABC/My company divisoin 21/my company place 12/department/place of work 876/876/93af/sdxd453215')
('643', 'Organitation/My Companies/company ABC/My company divisoin 21/my company place 12/department/place of work 876/876/93af/sdxd453215');
Output:
234,place of work 234
567, place of work 433
876,place of work 7654
543,place of work 876
643,place of work 876