我试图在访问环境中使用以下查询无济于事。问题似乎与APPLY有关。但是,这可以直接在我们的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
答案 0 :(得分: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)