我有以下选择语句:
SELECT projectid,documentid,revisionno,configurationid,variable45,
ISNULL(Variable45, (SELECT TOP 1 variable45 FROM pivot_table WHERE documentid = t.documentid and projectid=t.projectid
and configurationid=t.configurationid and cast(revisionno as int) < cast(t.revisionno as int) AND Variable45 is NOT NULL
ORDER BY projectid desc,documentid desc ,revisionno desc,configurationid desc)) as NewCol
FROM pivot_table t;
我尝试通过以下方式转换为更新,但我得到了错误的记录更新。谁能帮我解决我的问题:
UPdate PIVOT_TABLE
set variable45 = ((SELECT TOP 1 variable45 FROM pivot_table t WHERE t.documentid = documentid and t.projectid=projectid
and t.configurationid=configurationid and cast(t.revisionno as int) < cast(revisionno as int) AND Variable45 is NOT NULL
ORDER BY revisionno desc)) where Variable45 is NULL;
数据库:SQLExpress2008。
请指教。谢谢你。