删除尾部管道分隔符和中间的管道

Removing trailing pipe delimiter and pipe in between

我正在将三个 phone 由竖线分隔符分隔的数字加载到 Teradata DWH 中的列。

  1. 如果一行中所有三个 phone 数字都存在,值应该 看起来像这样 123 | 456 | 789.
  2. 如果存在第一个和第三个,则 123 | 789
  3. 如果 first 和 second 存在,则 123 | 456
  4. 如果存在第二个和第三个,则 456 | 789.

写入的查询有一些问题,如果缺少任何 phone 数字,请说如果第二个 phone 数字丢失,它正在存储这样的值 123 | | 789或者如果缺少第三个 phone 数字,则它给出 123 | 456 |.

我们不想要尾部管道或中间的 2 个管道。请建议一个 Teradata 查询来实现这个。

逻辑是:

对每列分配不同的权重,然后计算所有 3 列的长度的加权和。假设每个 phone 号码的长度为 10 位。这里是 query/pseudocode.

查询:

Select
case 1*LENGTH(firstCol)+2*LENGTH(secondCol)+4*LENGTH(thirdCol)
when 70 then CONCAT( firstcol,'|', secondcol,'|', thirdCol)  
when 60 then CONCAT( secondcol, '|', thirdCol)
when 50 then CONCAT( firstcol, '|', thirdCol)
when 30 then CONCAT (firstcol, '|', secondcol)
when 10 then firstcol
when 20 then secondcol
when 40 then thirdCol
else null
end
from phoneNumbersTable