REPLACE函数,用于替换特定列中的部分字符串

时间:2019-03-15 09:04:39

标签: sql teradata-sql-assistant

我写了以下代码:

((SELECT SUM(noteAmount)
          FROM notes
          WHERE DATE_FORMAT(noteDate, '%d-%m-%Y') = DATE_FORMAT(note1.noteDate, '%d-%m-%Y') AND noteType = 'in')
        -
        (SELECT SUM(noteAmount)
         FROM notes
         WHERE DATE_FORMAT(noteDate, '%d-%m-%Y') = DATE_FORMAT(note1.noteDate, '%d-%m-%Y') AND noteType = 'out')) as trxCount

这应该在WHERE语句的给定时间段内使用表SELECT * FROM BMD_MI_OPS.DBH_TELEFONIE WHERE cast(DATUM_TIJD as date) BETWEEN 1180212 AND 1180217; UPDATE BMD_MI_OPS.DBH_TELEFONIE SET QUEUE_NAAM = REPLACE(QUEUE_NAAM, '_DVB', ''); 的所有列。然后,它将擦除列BMD_MI_OPS.DBH_TELEFONIE中出现的每个_DVB。例如,QUEUE_NAAM应该变成VQ_PAR_EC_00_DVB

我想我做错了,对完成此操作的任何帮助将不胜感激。

谢谢。

1 个答案:

答案 0 :(得分:2)

您的语句未链接,如果要更新数据,则需要在WHERE中添加UPDATE子句

例如:

UPDATE BMD_MI_OPS.DBH_TELEFONIE 
SET QUEUE_NAAM = REPLACE(QUEUE_NAAM, '_DVB', '')
WHERE CAST(DATUM_TIJD AS DATE) BETWEEN 1180212 AND 1180217;

在更新之前选择行对您的更新没有影响,只是SELECT