2012-08-09 3 views
0

을 조인 나는 다음과 같은 select 문이 : 나는 업데이트 stement에 다음과 같은 방식으로 변환 시도TSQL로 변환을 선택 문

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; 

DB : SQLExpress2008.

알려 주시기 바랍니다. 고맙습니다.

답변

0

OK 나는 그것을 알아 냈 :

UPdate pt 
    set pt.variable45 = ((SELECT TOP 1 t.variable45 FROM pivot_table t WHERE 
t.documentid = pt.documentid and t.projectid=pt.projectid and t.configurationid=pt.configurationid and cast(t.revisionno as int) < cast(pt.revisionno as int) AND t.variable45 is NOT NULL 
      ORDER BY revisionno desc)) from PIVOT_TABLE pt where pt.variable45 is NULL;