;WITH K_RT_MasterRetailStoresTable (CommonId,Branch) AS
(
SELECT ROW_NUMBER() OVER(ORDER BY Branch) AS CommonId,Branch
FROM K_RT_MasterRetailStores
)
,K_BR_AddBranchTable (CommonId, branch) AS
(
SELECT ROW_NUMBER() OVER(ORDER BY branch) AS CommonId,branch
FROM K_BR_AddBranch
)
,K_HM_BranchTable (CommonID,branch) as
(
SELECT ROW_NUMBER() OVER(ORDER BY branch) as CommonId,branch
FROM K_HM_Branch
)
,k_Master_BranchesTable (CommonID, branch) as
(
SELECT ROW_NUMBER() OVER(ORDER BY BRANCH) AS COMMONID,BRANCH
FROM k_Master_Branches
)
SELECT MRS.BRANCH,AB.BRANCH,B.BRANCH,MB.BRANCH
FROM K_RT_MasterRetailStoresTable MR
LEFT OUTER JOIN K_BR_AddBranchTable AB ON MR.COMMONID = AB.COMMONID
LEFT OUTER JOIN K_HM_BranchTable B ON AB.COMMONID = B.COMMONID
LEFT OUTER JOIN k_Master_BranchesTable MB ON B.COMMONID = MB.COMMONID
這裏它顯示4列,4分支數據..但我想顯示單列所有分支data..how我可以做到這一點嗎?如何組合沒有公共列字段的兩個表?
爲什麼用'和'在外部連接,因爲之後沒有指定'和'條件? – Milen
我刪除了,現在它的執行..它顯示4列4個不同的表..現在我想只顯示所有分支中的單列..如何寫..請幫助我嗎? – Sambasiva