使用WHERE和LIKE的SQL Server更新

时间:2017-10-05 20:12:34

标签: sql sql-server replace sql-like

我有这个代码似乎不适用于REPLACE。我在这里遗漏了什么

UPDATE EMIR
SET Series = CL.Underlying_Security_Name
FROM EMIR e
INNER JOIN CALYPSO cl
    ON e.Internal_ID = cl.Trade_ID
    AND e.Internal_ID_Type = 'CL'
    WHERE cl.Underlying_Security_Name like 'CMBX.NA.%'REPLACE((SUBSTRING(REPLACE(Underlying_Security_Name,'CMBX.NA.',''),CHARINDEX('.',REPLACE(Underlying_Security_Name,'CMBX.NA.',''))+1,2)),'.',''))

2 个答案:

答案 0 :(得分:2)

你有一个更大的问题。您需要update FROM子句中定义的别名,而不是表格。

replace()您的问题可能需要字符串连接:

UPDATE e
    SET Series = CL.Underlying_Security_Name
FROM EMIR e INNER JOIN
     CALYPSO cl
     ON e.Internal_ID = cl.Trade_ID AND e.Internal_ID_Type = 'CL'
WHERE cl.Underlying_Security_Name like 'CMBX.NA.%' + REPLACE((SUBSTRING(REPLACE(Underlying_Security_Name,'CMBX.NA.',''), CHARINDEX('.', REPLACE(Underlying_Security_Name,'CMBX.NA.',''))+1,2)),'.',''))

答案 1 :(得分:0)

UPDATE emir
    SET Series = (select CL.Underlying_Security_Name
FROM EMIR e, 
     CALYPSO cl
     Where
 e.Internal_ID(+)  = cl.Trade_ID AND e.Internal_ID_Type = 'CL'
And cl.Underlying_Security_Name like 'CMBX.NA.%'REPLACE((SUBSTRING(REPLACE(Underlying_Security_Name,'CMBX.NA.',''),CHARINDEX('.',REPLACE(Underlying_Security_Name,'CMBX.NA.',''))+1,2)),'.',''))

不确定替换,但修改上面的其余代码