如果在Mule中编写的查询中SQL Server查询中已有值,那么如何将空值更新为列?有效负载包含Data weave的结果集。在更新时,我想检查更新值是否为null,如果它“not null”,则只应更新值。
查询是:
UPDATE dbo.ix_str_store
SET NAME = '#[payload.Site.Name]',
ADDRESS1 = '#[payload.Site.Address1]',
ADDRESS2 = '#[payload.Site.Address2]',
ADDRESSCITY = '#[payload.Site.AddressCity]',
ADDRESSSTATE = '#[payload.Site.AddressState]',
ADDRESSPOSTALCODE = '#[payload.Site.AddressPostalCode]',
ADDRESSCOUNTRY = '#[payload.Site.AddressCountry]',
EMAIL = '#[payload.Site.Email]',
PHONE = '#[payload.Site.Phone]',
FAX = '#[payload.Site.Fax]',
REGION = '#[payload.Site.Region]',
COMPANY = '#[payload.Site.Company]',
DESC1 = '#[payload.Site.Desc1]',
DESC2 = '#[payload.Site.Desc2]',
DESC7 = '#[payload.Site.Desc7]',
DESC8 = '#[payload.Site.Desc8]',
VALUE1 = #[payload.Site.Value1],
VALUE2 = #[payload.Site.Value2],
DBTIME = CURRENT_TIMESTAMP,
DBSTATUS = 1
WHERE
STORENUMBER = #[payload.Site.StoreNumber]
答案 0 :(得分:1)
试试吧
isnull(new_value,old_value)
答案 1 :(得分:0)
在这种情况下,而不是使用insert into (...) values(...)
构造;使用insert into .. select from
构造如
insert into table (..)
select ..,
case when new_col_val is not null then new_col_val else old_col_val end
from ...
(或)您也可以使用COALESCE()
函数代替CASE
表达coalesce(new_col_val, old_col_val)