2017-05-27 105 views
-1

SQL查詢:SQL:更新數據透視表

SELECT id,mti,[24] AS nii,mid,tid,[63-D9] AS TxnType,[63-DB] AS batchStatus , 
[39] AS respondCode,[61] AS batchNumber, uploadStatus 
FROM (SELECT e.id,m.capDateTime,mti,procCode,mid,tid,uploadStatus,txnDate,txnTime,fieldNumber,fieldData FROM dbo.iso_fields e 
JOIN dbo.iso_main m ON e.id = m.id) a PIVOT (MAX(fieldData) FOR fieldNumber IN 
([0],[1],[2],[3],[5],[6],[7],[8],[9],[10],[12],[13],[14],[15],[16],[17],[18],[19],[20], [21],[22],[23],[24],[25],[26],[27],[28],[29],[30], 
[31],[32],[33],[34],[35],[36],[39],[40], [41],[42],[43],[44],[45],[46],[47],[48],[49],[50],[51],[52],[53],[54],[55],[56],[57],[58],[59],[60], 
[61],[63],[64],[63-D9],[63-DB]))PIV 

我試着去更新例如表:

UPDATE PIV SET batchStatus = 'C' 
    SELECT id,mti,[24] AS nii,mid,tid,[63-D9] AS TxnType,[63-DB] AS batchStatus , 
    [39] AS respondCode,[61] AS batchNumber, uploadStatus 
    FROM (SELECT e.id,m.capDateTime,mti,procCode,mid,tid,uploadStatus,txnDate,txnTime,fieldNumber,fieldData FROM dbo.iso_fields e 
    JOIN dbo.iso_main m ON e.id = m.id) a PIVOT (MAX(fieldData) FOR fieldNumber IN 
    ([0],[1],[2],[3],[5],[6],[7],[8],[9],[10],[12],[13],[14],[15],[16],[17],[18],[19],[20], [21],[22],[23],[24],[25],[26],[27],[28],[29],[30], 
    [31],[32],[33],[34],[35],[36],[39],[40], [41],[42],[43],[44],[45],[46],[47],[48],[49],[50],[51],[52],[53],[54],[55],[56],[57],[58],[59],[60], 
    [61],[63],[64],[63-D9],[63-DB]))PIV 
WHERE nii = '0000' 

Im相當肯定是不正確的語法和IM在如此可怕的數據透視表的

+0

您正在使用哪些DBMS? 「SQL」是一種查詢語言,而不是特定DBMS產品的名稱(另外:您的示例查詢是無效的標準SQL) –

回答

0

查看您的查詢後,似乎您正在更新一個不可能的PIVOT「PIV」。數據透視僅帶有聚合子句。你無法更新它。

如果我正確理解你的問題,你想刷新PIVOT數據,如果這個假設是正確的,那麼你需要更新你在PIVOT中使用的主表或者使用臨時表來反映更新的數據。