我想在触发器中动态构建一个 UPDATE 语句,所以我需要一些临时变量和长度相关函数的帮助,并使用临时变量来指定 UPDATE 语句中的字段/更新值:
stSQL as string
stSQL = ""
IF FieldA=<criteria> then
stSQL = "FieldB = we_ci_db.dbo.ztblTest.FieldA"
endif
IF FieldG=<criteria> then
if len(stSQL)>0 then stSQL=stSQL & " AND "
stSQL = "FieldH = we_ci_db.dbo.ztblTest.FieldF"
else
if len(stSQL)>0 then stSQL=stSQL & " AND "
stSQL = "FieldH = we_ci_db.dbo.ztblTest.FieldG"
endif
UPDATE ztblTest
SET stSQL
WHERE TestID IN (SELECT DISTINCT TestID FROM inserted)