如何在這段代碼中使用合併命令下面的代碼如何使用聚結在,在那裏部分
PIECE_DETAIL in coalesce(PIECE_DETAIL, (SELECT B.MODEL_ID FROM PIECES_DETAILS B WHERE PIECE_ID = @PIECE_ID AND B.BRAND_ID=COALESCE(B.BRAND_ID,@BRAND_ID))
SELECT DISTINCT
[dbo].[test2](A.PIECE_DETAIL ) TOTAL_QUANTITY,
PIECE_LATIN = (SELECT PIECE_LATIN FROM PIECES WHERE PIECE_ID =
(SELECT PIECE_ID FROM PIECES_DETAILS WHERE MODEL_ID = A.PIECE_DETAIL)),
BRAND_LATIN = (SELECT BRAND_LATIN FROM BRANDS WHERE BRAND_ID =
(SELECT BRAND_ID FROM PIECES_DETAILS WHERE MODEL_ID = A.PIECE_DETAIL)),
BRAND_ID = (SELECT BRAND_ID FROM PIECES_DETAILS WHERE MODEL_ID = A.PIECE_DETAIL),
PIECE_ID = (SELECT PIECE_ID FROM PIECES_DETAILS WHERE MODEL_ID = A.PIECE_DETAIL),
MODEL_NAME = (SELECT MODEL_NAME FROM PIECES_DETAILS WHERE MODEL_ID = A.PIECE_DETAIL),
PIECE_DETAIL MODEL_ID,
A.PIECE_STATUS ,
PIECE_STATUS_Name = (SELECT STATUS_Name FROM PIECE_STATUS WHERE STATUS_ID = A.PIECE_STATUS) ,
A.PIECE_DETAIL
FROM DOCUMENT_ITEMS A
WHERE
PIECE_STATUS = 1 and
DOC_SEQ IN (SELECT DOC_SEQ FROM DOCUMENT_HEADER WHERE DOC_TYPE IN (1,3))
AND PIECE_DETAIL in coalesce(PIECE_DETAIL, (SELECT B.MODEL_ID FROM PIECES_DETAILS B WHERE PIECE_ID = @PIECE_ID AND B.BRAND_ID=COALESCE(B.BRAND_ID,@BRAND_ID))
AND [DBO].[GET_WAREHOUSE_QUANTITIES_SPECIAL_ID_EXIST](A.PIECE_DETAIL ,A.SPECIAL_ID)> 0
GROUP BY PIECE_DETAIL ,SPECIAL_ID ,PIECE_STATUS
感謝所有
可否請你多加一點洞察你的問題。 – 2012-03-08 07:54:25
@于爾根·d:我想如果PIECE_DETAIL不爲空,在條件方面由於其他原因的情況而言。感謝 – Pouya 2012-03-08 08:00:12