组合Access查询并转换为SQL Server

时间:2018-03-13 12:56:23

标签: sql-server ms-access-2010

我有三张桌子。

  • tkDetail
  • LD
  • EM(仅用于提取名字和姓氏)

我在MS Access中查询了第一个表:

SELECT 
    dbo_tkDetail.WBS1, dbo_tkDetail.LaborCode, dbo_tkDetail.TransDate, 
    [LastName]+','+' '+[FirstName] AS Name, dbo_tkDetail.RegHrs, 
    dbo_tkDetail.OvtHrs, dbo_tkDetail.BillExt
FROM 
    dbo_tkDetail 
INNER JOIN 
    dbo_EM ON dbo_tkDetail.Employee = dbo_EM.Employee
WHERE 
    (((dbo_tkDetail.WBS1) Not Like '9%' And (dbo_tkDetail.WBS1) Not Like 'I%'));

我这样询问第二个:

SELECT 
    dbo_LD.WBS1, dbo_LD.LaborCode, dbo_LD.Employee, dbo_LD.TransDate, 
    dbo_LD.Name, dbo_LD.RegHrs, dbo_LD.OvtHrs, dbo_LD.BillExt
FROM 
    dbo_LD;

然后我查询了这些查询:

SELECT 
    [Time Keeper Detail].WBS1, [Time Keeper Detail].LaborCode, 
    [Time Keeper Detail].TransDate, [Time Keeper Detail].Name, 
    [Time Keeper Detail].RegHrs, [Time Keeper Detail].OvtHrs, 
    [Time Keeper Detail].BillExt
FROM 
    [Time Keeper Detail] 
LEFT JOIN 
    [Labor Detail] ON ([Time Keeper Detail].[Name] = [Labor Detail].[Name])   
                   AND ([Time Keeper Detail].TransDate = [Labor Detail].TransDate)
WHERE 
    ((([Labor Detail].Name) Is Null));

这是我能够达到我需要的结果集的唯一方法。

现在我需要将这三个查询合并为一个并转换为SQL服务器以从数据建模器运行它。我被卡住了。

1 个答案:

答案 0 :(得分:0)

这是一个完整的猜测,但我认为你所追求的是这个(我不知道你的意思是“查询查询”,但我猜错了):

SELECT D.WBS1,
       D.LaborCode,
       D.TransDate, 
       EM.[LastName]+','+' '+ EM.[FirstName] AS [Name], --Guessed the object these come from here
       D.RegHrs, 
       D.OvtHrs,
       D.BillExt
FROM dbo_tkDetail D
     INNER JOIN dbo_EM EM ON D.Employee = EM.Employee
     LEFT JOIN  dbo_LD LD ON E.[LastName]+','+' '+ E.[FirstName] = LD.[name]
                         AND D.TransDate = LD.TransDate
WHERE D.WBS1 NOT LIKE '9%'
  AND D.WBS1 NOT LIKE 'I%'
  AND LD.[Name] IS NULL;