String ard sql?:) Replace(CustomerName, 'ABC', 'XYZ') Replace(CustomerName, 'PLO', 'Rustic') Replace(CustomerName, 'Kix', 'BowWow') R

String ard sql?:) Replace(CustomerName, 'ABC', 'XYZ') Replace(CustomerName, 'PLO', 'Rustic') Replace(CustomerName, 'Kix', 'BowWow') R,string,replace,google-bigquery,String,Replace,Google Bigquery,ard sql?:) Replace(CustomerName, 'ABC', 'XYZ') Replace(CustomerName, 'PLO', 'Rustic') Replace(CustomerName, 'Kix', 'BowWow') REPLACE( REPLACE( REPLACE( CustomerName, 'ABC', 'XYZ'), 'PLO', 'Rustic'), 'Kix', 'BowWo

ard sql?:)
Replace(CustomerName, 'ABC', 'XYZ')
Replace(CustomerName, 'PLO', 'Rustic')
Replace(CustomerName, 'Kix', 'BowWow')
REPLACE(
  REPLACE(
    REPLACE(
      CustomerName,
      'ABC',
      'XYZ'),
    'PLO',
    'Rustic'),
  'Kix',
  'BowWow')
SELECT CustomerName, fixedCustomerName FROM JS(
// input table
(
  SELECT
    CustomerName, Replacements
  FROM YourTable
  CROSS JOIN (
    SELECT 
      GROUP_CONCAT_UNQUOTED(CONCAT(Word, ',', Replacement), ';') AS Replacements
    FROM ReplacementLookup
) ,
// input columns
CustomerName, Replacements,
// output schema
"[
{name: 'CustomerName', type: 'string'},
{name: 'fixedCustomerName', type: 'string'}
]",
// function
"function(r, emit){
  var Replacements = r.Replacements.split(';');
  var fixedCustomerName = r.CustomerName;
  for (var i = 0; i < Replacements.length; i++) {
    var pat = new RegExp(Replacements[i].split(',')[0],'gi')
    fixedCustomerName = fixedCustomerName.replace(pat, Replacements[i].split(',')[1]);
  }
  emit({CustomerName: r.CustomerName,fixedCustomerName: fixedCustomerName});
 }"
)
SELECT CustomerName, fixedCustomerName FROM JS(
// input table
(
  SELECT
    CustomerName, Replacements
  FROM (
    SELECT CustomerName FROM
      (SELECT '1234ABC567' AS CustomerName),
      (SELECT '12 34 PLO 56' AS CustomerName),
      (SELECT 'Kix' AS CustomerName),
      (SELECT '98 ABC PLO Kix ABC 76 XYZ 54' AS CustomerName),
      (SELECT 'ABCQweKIX' AS CustomerName)
  ) YourTable
  CROSS JOIN (
    SELECT 
      GROUP_CONCAT_UNQUOTED(CONCAT(Word, ',', Replacement), ';') AS Replacements
    FROM (
      SELECT Word, Replacement FROM
        (SELECT 'XYZ' AS Word, 'QWE' AS Replacement),
        (SELECT 'ABC' AS Word, 'XYZ' AS Replacement),
        (SELECT 'PLO' AS Word, 'Rustic' AS Replacement),
        (SELECT 'Kix' AS Word, 'BowWow' AS Replacement)
    )
  ) ReplacementLookup
) ,
// input columns
CustomerName, Replacements,
// output schema
"[
{name: 'CustomerName', type: 'string'},
{name: 'fixedCustomerName', type: 'string'}
]",
// function
"function(r, emit){
  var Replacements = r.Replacements.split(';');
  var fixedCustomerName = r.CustomerName;
  for (var i = 0; i < Replacements.length; i++) {
    var pat = new RegExp(Replacements[i].split(',')[0],'gi')
    fixedCustomerName = fixedCustomerName.replace(pat, Replacements[i].split(',')[1]);
  }
  emit({CustomerName: r.CustomerName,fixedCustomerName: fixedCustomerName});
 }"
)
# Replace the support_table table with your actual table
WITH support_table AS (
    SELECT "ABC" AS OldValue, "XYZ" AS NewValue
)
SELECT main_table.OldValue, support_table.NewValue FROM main_table
JOIN support_table ON main_table.old_value = support_table.old_value
# Replace the values_to_replace table with your actual table
WITH values_to_replace AS (
   SELECT "item1" AS ColumnWithItemsToReplace
   UNION ALL
   SELECT "item2"
   UNION ALL
   SELECT "item3"
)
SELECT STRING_AGG(ColumnsWithItemsToReplace,"|") FROM values_to_replace
SELECT r"item1|item2|item3"
REGEXP_REPLACE(
 column_to_replace
,(SELECT STRING_AGG(ColumnWithItemsToReplace,"|") FROM `YourTable`)
,"Replacer"
)