1

我试图在访问环境中使用以下查询无济于事。问题似乎与应用有关。但是,这直接在我们的 SQL 服务器上运行良好..... 帮助?

SELECT 
    dbo_tblmain.key1, 
    dbo_tblmain.key2, 
    dbo_tblmain.data1, 
    dbo_tblmain.data2, 
    dbo_tblmain.data3, 
    dbo_tblsupp.data1,
    tbloutmade.data1
FROM dbo_tblmain 
LEFT JOIN dbo_tblsupp 
ON (dbo_tblmain.key1 = dbo_tblsupp.key1) AND (dbo_tblmain.key2 = dbo_tblsupp.key2)
OUTER APPLY 
(SELECT TOP 1 * FROM dbo_tbloutside WHERE LEFT(dbo_tblmain.key1,14)=LEFT(dbo_tbloutside.key1,14)) tbloutmade;

样本数据

tblmain
key1          key2                data1 data2 data3 
A1234567890   12345678901234AAA   AAA   BBB   CCC   

tblsupp
key1          key2                data1
A1234567890   12345678901234AAA   DDD

tbloutside
key1                 data1
12345678901234AAABB  EEE
4

1 回答 1

2

你可以试试:

SELECT 
    dbo_tblmain.key1, 
    dbo_tblmain.key2, 
    dbo_tblmain.data1, 
    dbo_tblmain.data2, 
    dbo_tblmain.data3, 
    dbo_tblsupp.data1,
    (SELECT TOP 1 Key1 FROM dbo_tbloutside 
     WHERE LEFT(dbo_tblmain.key1,14)=LEFT(dbo_tbloutside.key1,14)) As tbloutmade
FROM dbo_tblmain 
LEFT JOIN dbo_tblsupp 
ON (dbo_tblmain.key1 = dbo_tblsupp.key1) 
AND (dbo_tblmain.key2 = dbo_tblsupp.key2)
于 2012-09-24T19:16:05.223 回答