How to select a string between two strings in a column in SQL Server?

Viewed 12669

I want to get the string between two strings in a column of a table. How can I select the column? I have written the strings which are on either side. Can anyone help me how to include the column name with the string here?

DECLARE @Text NVARCHAR(MAX)

SELECT 
    SUBSTRING(@Text, CHARINDEX('Manufacturer Name : ', @Text), 
                     CHARINDEX('Manufacturer Part',@text) - CHARINDEX('Manufacturer Name : ', @Text) + LEN('Manufacturer Part')) 
FROM 
    tbIMPACArchiveNew 
WHERE 
    (Description LIKE '%Manufacturer Name: %' 
     OR Description LIKE '%Manufacturer Name : %') 
    AND Description LIKE '%Manufacturer Part%' 

Expected result:

Column A                                                       Expected result
Manufacturer Name : ABC Manufacturer Part Number : XVB-C2B4         ABC
Manufacturer Name : DEF Manufacturer Part Number : 3RH1924-1GP11    DEF
Manufacturer Name : ABJ Manufacturer Part Number : FLDP-IOM248-0001 ABJ
Manufacturer Name : HIJ Manufacturer Part Number : L12/5MLLD0035    HIJ
Manufacturer Name : abhkdk Manufacturer Part Number : PEH1083510    abhkdk
Manufacturer Name : 1245 PUMP Manufacturer Part Number : 02-1010-55 1245
4 Answers
Related