I have this data in my table
PartNumber | IsValid
BC.QT.000002' 0
'CP.AC.'000010' 0
'CP.AL.000013 0
'CP.A'L.000016' 0
'CP.AL.000024' 0
What I am trying to do is to remove the ' from PartNumber value, but if that quote ' is in the middle of the value for example 'CP.AC.'000010' I only want to remove the suffix and the prefix '
The desired result would look something like this
PartNumber | IsValid
BC.QT.000002 0
CP.AC.'000010 0
CP.AL.000013 0
CP.A'L.000016 0
CP.AL.000024 0
Here is the SQL that I tried
CREATE TABLE #Temp(
PartNumber VARCHAR(20)
,Test VARCHAR(30)
);
INSERT INTO #Temp(PartNumber,Test) VALUES ('''test''',NULL);
INSERT INTO #Temp(PartNumber,Test) VALUES ('''te''st2''',NULL);
INSERT INTO #Temp(PartNumber,Test) VALUES ('''test3''',NULL);
INSERT INTO #Temp(PartNumber,Test) VALUES ('''tes''t5''',NULL);
Update #Temp
set partNumber = REPLACE(PartNumber,'''','')
Where len(partNumber ) - len(replace(partNumber , '''', '')) = 2
This does not work because it completely ignores values where the there is 3 ' in the value, or if there are 2 ' but one of them in the middle.
I need a way to remove the prefix/suffix ' if they exist.