我真的希望你能帮我解决这个问题。我正在尝试根据旧字段长度是否大于一个来运行两种不同的更新查询。这背后的想法是,当用户更新产品时,它会将 ProductRef 附加到纯粹用于搜索的搜索表中。
很简单,如果 ProductRef 的字符串长度大于 0,则将旧的产品 ref 替换为新的。否则,添加新产品参考。这是我到目前为止所拥有的,但它似乎触发了一个错误 -
-- Update the ProductType UpdatedTS that corresponds with this product
-- The below section simply updates the main products UpdatedTS
UPDATE tbl_product_types
SET UpdatedTS = now()
WHERE ID = New.ProductTypeID;
IF ( SELECT Length(Old.ProductRef) > 0 )
BEGIN
-- We have already stored the product reference so run a replace
UPDATE tbl_product_type_search AS STable
SET `STable.Search` = replace(`Search`,CONCAT(Old.ProductRef,' '),New.ProductRef)
WHERE `STable.ProductTypeID` = Old.ProductTypeID
END
ELSE
BEGIN
-- We haven't yet stored the product reference, store it
UPDATE tbl_product_type_search AS STable
SET `STable.Search` = CONCAT(NEW.ProductRef,' ',`STable.Search`)
WHERE STable.ProductTypeID = New.ProductTypeID
END
供您参考,以下是相关的数据库结构: