well, here's one way - but just for the data you posted. The problem with transforming vendor data is who knows what will show up in these fields. And this code below will break if the value doesn't contain a comma so I'm sure there are a lot of tweaks that will need to be made with the real data.Assumes you will have a [States] table with your state abbreviations. And that you will load the raw data into a staging table.;with staging (cityState)as( select 'ATLANTA,GA AIRPORT ONSITE' union all select 'BETHLEHEM, PA' union all select 'ANCHORAGE, AK No Ship HazMat' union all select 'FOREST PARK, GA' union all select 'HUNTINGTON,WV No Ship'), states (mnemonic)as( select 'GA' union all select 'PA' union all select 'WV' union all select 'AK' union all select 'RI')select left(cityState, charindex(',', cityState)-1) as PlantName ,left(cityState, charindex(',', cityState)-1) as City ,st.mnemonicfrom staging sgleft outer join states st on st.mnemonic = substring(replace(sg.cityState,', ',','), charindex(',', sg.cityState)+1, 2) OUTPUT:PlantName City mnemonic---------------------------- ---------------------------- --------ATLANTA ATLANTA GABETHLEHEM BETHLEHEM PAANCHORAGE ANCHORAGE AKFOREST PARK FOREST PARK GAHUNTINGTON HUNTINGTON WV
Be One with the OptimizerTG