2
這段代碼產生這樣的結果選擇查詢生成的結果,但不是如果
SELECT PER.GLACCOUNT, PER.PERIOD,(SELECT GL.[CLOSING_CREDIT]
FROM [EMBDATA].[DBO].[_EMB_GL_ACTUALVALUESTYP] AS GL
WHERE GL.PERIOD = (DBO.GETMAXPERIOD(PER.GLACCOUNT,PER.PERIOD))
AND GL.ID COLLATE SQL_Latin1_General_CP1_CS_AS =
COLLATE SQL_Latin1_General_CP1_CS_AS) AS BALANCE
FROM [DBO].[GL_PERIOD_BAL] AS PER
WHERE LEFT(PER.GLACCOUNT,4) = 'NM01' AND [BAL.TYPE] = 'R'
ORDER BY PER.GLACCOUNT,PER.PERIOD GLACCOUNT PERIOD BALANCE)
結果
NM01-4100-0015 2015-12 7081557.0000
NM01-4100-0016 2015-12 0.0000
NM01-4100-0017 2015-12 0.0000
NM01-4100-0018 2015-12 12329577.0000
NM01-4100-0019 2015-12 1622830124.0000
NM01-4100-0020 2015-12 0.0000
NM01-4100-0021 2015-12 23747.0000
NM01-4100-0022 2015-12 0.0000
NM01-4100-0023 2015-12 1623014.0000
但是,如果我想將它合併到一個更新語句,它不是」更新子句中使用t更新 的代碼。
UPDATE [DBO].[GL_PERIOD_BAL]
SET [CLOSING_CREDIT] = (SELECT GL.[CLOSING_CREDIT]
FROM [EMBRACEDATA].[DBO].[_EMB_GL_ACTUALVALUESTYP] GL
WHERE GL.PERIOD = (DBO.GETMAXPERIOD(GLACCOUNT,PERIOD))
AND GL.ID COLLATE SQL_Latin1_General_CP1_CS_AS =
GLACCOUNT COLLATE SQL_Latin1_General_CP1_CS_AS)
WHERE LEFT(GLACCOUNT,4) = 'NM01' AND [BAL.TYPE] = 'R'