I doubt all your data will be this cleanly formatted but this might get you most of the way there:set nocount oncreate table #customer (custID int, custName varchar(15), custAddress varchar(40), city varchar(15), state varchar(2))goinsert #customerselect 1, 'CustomerABC', '4 Main Road, Irvine, CA', 'Irvine', 'CA' union allselect 2, 'CustomerDEF', '123 Boundary Street, New York, NY', 'New York', 'NY' union allselect 3, 'CustomerXYZ', '8 25th Avenue, San Francisco, CA', 'San Francisco', 'CA'goalter table #customer add address1 varchar(30)goupdate #customer set address1 = substring(replace(replace(custAddress, ', ' + city, ''), ', ' + state, ''),1,30)from #customerselect custid ,custname ,address1 ,city ,statefrom #customerdrop table #customeroutput:custid custname address1 city state ----------- --------------- ------------------------------ --------------- ----- 1 CustomerABC 4 Main Road Irvine CA2 CustomerDEF 123 Boundary Street New York NY3 CustomerXYZ 8 25th Avenue San Francisco CA
Be One with the OptimizerTG