0
我如何加入這兩個查詢加入兩個表
SELECT
GLMA_COMP_CODE COMP,
GLMA_ACCT_CODE ACCOUNT_NO,
GLMA_DEPT_NO DEPT,
GLMA_ACCT_NAME ACCOUNT_NAME
FROM GLAS_GL_MASTERS
WHERE GLMA_COMP_CODE = @COMP_CODE
AND GLMA_YEAR = CONVERT(NUMERIC(8, 2), DATEPART(YYYY, @DATE_FROM))
AND GLMA_ACCT_CODE BETWEEN ISNULL(@ACCT_CODE_FROM, GLMA_ACCT_CODE) AND
ISNULL(@ACCT_CODE_TO, GLMA_ACCT_CODE)
ORDER BY GLMA_ACCT_CODE
SELECT
GLTR_COMP_CODE,
GLTR_DEPT_NO,
GLTR_ACCT_CODE,
CAST(GLTR_PSTNG_TYPE AS VARCHAR) + CAST(GLTR_PSTNG_NO AS VARCHAR) REF_NO,
CAST(GLTR_DOC_CODE AS VARCHAR) + CAST(GLTR_OUR_DOC_NO AS VARCHAR) DOC_NO,
GLTR_DOC_DATE DOC_DATE,
GLTR_DOC_NARR NARRATIVE,
GLTR_PSTNG_DATE,
CASE SIGN(GLTR_TRAN_AMT)
WHEN + 1 THEN GLTR_TRAN_AMT
ELSE 0
END DEBIT,
CASE SIGN(GLTR_TRAN_AMT)
WHEN - 1 THEN GLTR_TRAN_AMT
ELSE 0
END CREDIT,
GLTR_TRAN_AMT AMOUNT,
GLTR_FC_CODE FC_CODE,
GLTR_FC_AMT FC_AMOUNT
FROM GLAS_GL_TRANSACTIONS
WHERE GLTR_PSTNG_DATE BETWEEN ISNULL(@DATE_FROM, GLTR_PSTNG_DATE) AND ISNULL(@DATE_TO, GLTR_PSTNG_DATE)
ORDER BY GLTR_ACCT_CODE,
GLTR_PSTNG_DATE,
GLTR_DOC_CODE,
GLTR_OUR_DOC_NO
我們不知道你的數據模型 - 你有告訴我們這兩個表格之間哪些列是共同的。 – 2009-12-23 08:02:40