我正在尝试使用链接的Oracle数据库和数据库中的SQL表和表创建视图。 SQL部分如下
SELECT empv.FULL_NAME,
CAST(C_Date + ' ' + SUBSTRING(C_Time, 1, 2) + ':' + SUBSTRING(C_Time, 3, 2) + ':'
+ SUBSTRING(C_Time, 5, 2) AS DATETIME) AS "PUNCH_TIME",
tT.C_Name "MACHINE_NAME",
CASE
WHEN LEN(L_UID) < 4 THEN RIGHT('0000' + CAST(L_UID AS VARCHAR(4)), 4)
ELSE CAST(L_UID AS VARCHAR(10))
END AS "EMPLOYEE_NUMBER",
CASE L_MODE
WHEN 1 THEN 0
WHEN 2 THEN 1
ELSE L_MODE
END AS "PUNCH_TYPE",
CASE L_RESULT
WHEN 0 THEN 'S'
ELSE 'E'
END AS "PUNCH_RESULT"
FROM tEnter T,
tTerminal tT,
[PRODBAK]..APPS.XXFPEMPVIEW empv
WHERE 1 = 1
AND tT.L_ID = T.L_TID
AND L_UID <> -1
AND empv.EMPLOYEE_NUMBER = T.L_UID
/* AND CAST(GETDATE() AS DATE) BETWEEN empv.effective_start_date and COALESCE(effective_end_date, CAST(getdate() as date))*/
AND CAST(C_Date + ' ' + SUBSTRING(C_Time, 1, 2) + ':' + SUBSTRING(C_Time, 3, 2) + ':' + SUBSTRING(C_Time, 5, 2) AS DATETIME)
BETWEEN empv.effective_start_date AND COALESCE(effective_end_date, CAST(GETDATE() AS DATE))
AND CAST(C_Date + ' ' + SUBSTRING(C_Time, 1, 2) + ':' + SUBSTRING(C_Time, 3, 2) + ':' + SUBSTRING(C_Time, 5, 2) AS DATETIME)
> '01/01/2016 00:00:00 AM'
GO
现在我遇到了一些问题,MS SQL表的用户ID值很少(L_UID),这些值与链接的Oracle表可用的EMPLOYEE_NUMBER列值不匹配。这会导致脚本长时间运行,并最终由于找不到值而放弃。我该如何克服这种情况?我对MS SQL很陌生,JOIN语法在这个时候对我来说很陌生。
答案 0 :(得分:1)
尝试替换:
FROM tEnter T,
tTerminal tT,
[PRODBAK]..APPS.XXFPEMPVIEW empv
WHERE 1 = 1
AND tT.L_ID = T.L_TID
AND L_UID <> -1
AND empv.EMPLOYEE_NUMBER = T.L_UID
使用
....
FROM tEnter T
LEFT JOIN tTerminal tT ON tT.L_ID = T.L_TID
Left JOIN [PRODBAK]..APPS.XXFPEMPVIEW empv ON empv.EMPLOYEE_NUMBER = T.L_UID
WHERE L_UID <> -1
...